小弟初学,请大家帮忙.因为要用到StringBuffer里面的reverse()方法

解决方案 »

  1.   

    str = "123";
    StringBuffer sb = new StringBuffer(str);
      

  2.   

    String myString = "Read Doc Please";
    StringBuffer myBuffer = new StringBuffer(myString);
      

  3.   

    哈哈, 和bao110908(bao)冲了贴咯
      

  4.   

    但接收是从控制输入的...我的意思是想从控制台接受完了后 转换成StringBuffer 然后调用方法使得字符串回文... 写了个 但好像程序运行结果不对..大家有什么好办法么?
    public class Test3 {public static StringBuffer reverse(StringBuffer s) {return s.reverse();}public static void main(String[] args) throws Exception {InputStream in = System.in;Integer n=in.read();
            
    String ss=n.toString();StringBuffer s = new StringBuffer(ss);
            
    System.out.println(Test3.reverse(s));}}
      

  5.   

    public class StringBufferTest { /**
     * @param args
     */
    public static void main(String[] args) {
    String ss = "I am Robin";
    StringBuffer sb = new StringBuffer(ss);
    System.out.println(sb.reverse());
    }}
      

  6.   

    import java.io.*;public class Test4 {
    public static StringBuffer reverse(StringBuffer s) {
    return s.reverse();
    }
    public static void main(String[] args) throws Exception {
    InputStream in = System.in;
    byte []buf = new byte[1024];
    int length = in.read(buf);  //读到字节数组中,然后再放到String中操作
    String ss = new String(buf,0,length);
    StringBuffer s = new StringBuffer(ss);
    System.out.println(Test3.reverse(s));
    }
    }
      

  7.   

    import java.io.*;public class Test3 {public static StringBuffer reverse(StringBuffer s) {return s.reverse();}public static void main(String[] args) throws Exception {BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));   //另外一种读写方式String ss = buf.readLine();StringBuffer s = new StringBuffer(ss);System.out.println(Test3.reverse(s));}}
      

  8.   

    import java.io.InputStream;public class Test3 {
      private final static int MAX_LENGTH = 1000;  public static StringBuffer reverse(StringBuffer s) {
        return s.reverse();
      }  public static void main(String[] args) throws Exception {    InputStream in = System.in;
        byte[] bData = new byte[MAX_LENGTH];    Integer iCount = in.read(bData);    String ss = new String(bData, 0, iCount - 2);    StringBuffer s = new StringBuffer(ss);    System.out.println(Test3.reverse(s));  }}