关于在控制台中读取数字的问题

liuwei424 2008-01-24 05:04:37
我在控制台下写了如下代码:
System.out.println("输入数字:");
int s = System.in.read();
System.out.println("输出数字:"+ s);
但是有问题,我输入1,输出的是49;
我输入100,输出的也是49;
有没有什么方法使我输入什么数字,我读取的就是什么数字??
...全文
153 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoben008 2008-01-24
  • 打赏
  • 举报
回复
这样啊。。我也有点晕
liuwei424 2008-01-24
  • 打赏
  • 举报
回复
楼上的朋友,非常感谢,我已经明白了!
spectre62 2008-01-24
  • 打赏
  • 举报
回复
System.in.read(); 只读了一位,第1都都是1,数字1的asc码是49所以输出都是49

import java.io.*;
public class TestString {
public static void main(String args[]) {
InputStreamReader isr =
new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = null;
try {
s = br.readLine();
while(s!=null){
if(s.equalsIgnoreCase("exit")) break;
System.out.println(s);
s = br.readLine();
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
liuwei424 2008-01-24
  • 打赏
  • 举报
回复
请帮我回答一下!!!!!!!!!

62,623

社区成员

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

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