日期:2014-05-20  浏览次数:20706 次

对接受用户输入不理解 请高手指点下
Scanner in = new Scanner(System.in)和int jave =input.nextInt();


这两句话到底是什么意思 都是接受用户输入????

------解决方案--------------------
nextInt()只是等待***输入一个整型数据

Scanner 可就强大了
当reader=new Scanner(System.in)时,也就是构造方法的参数是System.in时; 
reader对象调用下列方法(函数),可以读取用户在命令行输入的各种数据类型: next.Byte(),nextDouble(),nextFloat,nextInt(),nextLin(),nextLong(),nextShot() 
上述方法执行时都会造成堵塞,等待用户在命令行输入数据回车确认.
例如,拥护在键盘输入12.34,hasNextFloat()的值是true,而hasNextInt()的值是false. NextLine()等待用户输入一个文本行并且回车,该方法得到一个String类型的数据。

此外sanner你可以重定向到其他输入流,而不是一定要System.in
------解决方案--------------------
方法总是很多的嘛,条条大路通罗马。
BufferedReader br = new BufferReader(new InputStreamReader(System.in));
br.readLine();