Scanner s=new Scanner(System.in);
String s=br.readLine();
while(?){
System.out.println(s);
s=br.readLine();
}while(?)应该写什么条件让它从键盘输入两个回车退出循环 我用了s!=null 和!s.equals(""); 都不行 这是什么原因 谢谢
String s=br.readLine();
while(?){
System.out.println(s);
s=br.readLine();
}while(?)应该写什么条件让它从键盘输入两个回车退出循环 我用了s!=null 和!s.equals(""); 都不行 这是什么原因 谢谢
用\\n来判断 Scanner是通过正则来读取输入的
Scanner br = new Scanner(System.in);
int count = 0;
while(count < 2){ //连续输入2个回车
if (br.nextLine().isEmpty()) count++;
else count = 0; //非连续的话重新清0
}