在使用scanner进行读取的时候,如果不知道输入是多少行,怎么办?
直接给出答案:
Scanner cin = new Scanner(System.in);
String s=null;
while(true){
if ((s = cin.nextLine()).equals(""))
break;
System.out.println(s);
}
System.out.println("out!!");
这样,如果某一行什么都没有输入,直接一个回车的话,就跳出while循环,执行你自己的代码了。