Topic: 请问如何获取输入的数字 |
Print this page |
1.请问如何获取输入的数字 | Copy to clipboard |
Posted by: qfeng Posted on: 2007-06-25 17:11 rt,请问在java中如何获取输入的数字,之前试过用System.in.read(),发现取到的只是第一个数字(例如输入56,只取到5),有没有什么函数能取到整个数字的? |
2.Re:请问如何获取输入的数字 [Re: qfeng] | Copy to clipboard |
Posted by: qfeng Posted on: 2007-06-26 09:43 rt,请问在java中如何获取输入的数字,之前试过用System.in.read(),发现取到的只是第一个数字(例如输入56,只取到5),有没有什么函数能取到整个数字的? |
3.Re:请问如何获取输入的数字 [Re: qfeng] | Copy to clipboard |
Posted by: xuxiaolei Posted on: 2007-06-26 13:03 public static void main( String args[] ) throws IOException { InputStreamReader reader = new InputStreamReader(System.in); BufferedReader buffer = new BufferedReader(reader); String line = buffer.readLine(); System.out.println(line); } |
4.Re:请问如何获取输入的数字 [Re: qfeng] | Copy to clipboard |
Posted by: qfeng Posted on: 2007-06-27 08:40 谢谢 xuxiaolei ,我在其他地方找到另一种方法,而且获取的数字不用转换就可用。 import java.util.*; public static void main( String args[] ) throws IOException { Scanner sc= new Scanner(System.in); System.out.println("Input the number:"); //输入数字 int num= sc.nextInt(); System.out.println(num); } |
5.Re:请问如何获取输入的数字 [Re: qfeng] | Copy to clipboard |
Posted by: hollyman Posted on: 2007-06-27 10:29 qfeng wrote: Scanner不用设置IOException的,并且对空格无效,不过你要的数字也无啥影响 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |