怎么读入一个int然后输出

iwdc 2005-10-25 10:39:07
这个好像牵涉到流的转换,直接输入然后输出的话得到的不是原来输入的值。
要怎么实现呢,谢谢。
...全文
150 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
scriptren 2005-10-26
  • 打赏
  • 举报
回复
system.in.read
Integer.parseInt
system.out.println
iwdc 2005-10-26
  • 打赏
  • 举报
回复
试了一下,masse(当午) 上面这个用BufferedReader实现的也是对的。谢谢你们。
iwdc 2005-10-26
  • 打赏
  • 举报
回复
f_acme(沧海一声笑)说的用Scanner来实现可行。
不过如果不用这个类,能不能实现呢? :)
yanxiazhiqiu 2005-10-26
  • 打赏
  • 举报
回复
learning~~~
zgysc 2005-10-26
  • 打赏
  • 举报
回复
int a = Integer.parseInt(s);
f_acme 2005-10-26
  • 打赏
  • 举报
回复
jdk1.5中

Scanner cin=new Scanner(System.in);
int a=cin.nextInt();
System.out.println(a);

Scanner类还可以读其他的数据类型,用于命令行下的输入特别好用.具体请看Javadoc.
masse 2005-10-25
  • 打赏
  • 举报
回复
public class Input{
public static void main(String[] args){
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = "";
while (str != null) {
str = in.readLine();
int a = Integer.parseInt(str.trim());
System.out.println("输入了:" + i);
}
} catch (Exception e) {
}
}
}
qxbnit 2005-10-25
  • 打赏
  • 举报
回复
键盘输入的话就是个char
char s=System.in.....
int a = Integer.parseInt(s);
masse 2005-10-25
  • 打赏
  • 举报
回复
输入字符串会吧?
得到字符串s
然后int a = Integer.parseInt(s);
就可以了

62,614

社区成员

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

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