但接收是从控制输入的...我的意思是想从控制台接受完了后 转换成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));}}
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()); }}
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)); } }
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));}}
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)); }}
StringBuffer sb = new StringBuffer(str);
StringBuffer myBuffer = new StringBuffer(myString);
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));}}
* @param args
*/
public static void main(String[] args) {
String ss = "I am Robin";
StringBuffer sb = new StringBuffer(ss);
System.out.println(sb.reverse());
}}
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));
}
}
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)); }}