新手问问题,大家帮忙看看程序哈

britneylove 2009-10-24 11:27:02
就是一个在命令行输入,逆序输出的小程序,调补出来。请大家帮忙改改,谢谢谢谢!!!

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class R{
public static void main(String args[]) {
BufferedReader buf = null;
buf = new BufferedReader(new InputStreamReader(System.in));
String str = null;
System.out.print("请输入内容: ");
try {
str = buf.readLine();
StringBuffer sb = new StringBuffer(str);
}catch(Exception e) {
e.printStackTrace();
}
System.out.println("输入的内容为: "+str);
System.out.println("逆序后的内容为: "+sb.reverse());
}
}
...全文
69 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
che5201314 2009-10-24
  • 打赏
  • 举报
回复
put the last two"system.out.print" in the "try "
Click_Me 2009-10-24
  • 打赏
  • 举报
回复

public static void main(String args[]) {
BufferedReader buf = null;
buf = new BufferedReader(new InputStreamReader(System.in));
String str = null;
System.out.print("请输入内容: ");
StringBuffer sb = new StringBuffer();
try {
str = buf.readLine();
sb.append(str);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("输入的内容为: " + str);
System.out.println("逆序后的内容为: " + sb.reverse());
}

tjb1216 2009-10-24
  • 打赏
  • 举报
回复
帮顶,貌似用Scanner会好点
britneylove 2009-10-24
  • 打赏
  • 举报
回复
谢谢各位高手哈,问题解决了,分给2楼帅哥吧

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧