自己参考下吧
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args){
BufferedReader br = null;
String s = "";
String s1 = "";
try{
br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入字符并以回车结束:");
//读入键盘输入
s = br.readLine();
StringBuffer ss = new StringBuffer(s);
ss.reverse();//StringBuffer类的逆序函数
s1 = ss.toString();
System.out.println("你输入的是:" + s);
System.out.println("逆序以后是:" + s1);
} catch (IOException e){
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
} finally{
try{
br.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}