Scanner

当通过new Scanner(System.in)创建一个Scanner,控制台会一直等待输入,直到敲回车键结束,把所输入的内容传给Scanner,作为扫描对象。如果要获取输入的内容,则只需要调用Scanner的nextLine()方法即可。

/** 
* 扫描控制台输入 

* @author leizhimin 2009-7-24 11:24:47 
*/ 
public class TestScanner { 
public static void main(String[] args) { 
Scanner s = new Scanner(System.in); 
System.out.println(“请输入字符串:”); 
while (true) { 
String line = s.nextLine(); 
if (line.equals(“exit”)) break; 
System.out.println(“…” + line); 


}

请输入字符串: 
234 
…234 
wer 
…wer 
bye 
…bye 
exit

Process finished with exit code 0

原文地址:https://www.cnblogs.com/deogao/p/5320543.html