1.while(sc.hasnext())
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {//Ctrl+z(d)结束循环
String s = sc.nextLine();
//......
}
2.while(true),循环里要有结束循环的条件!!!
Scanner sc = new Scanner(System.in);
while (true){
String s = sc.nextLine();
if(s.equals("end")){//保证有结束循环的条件
break;
//......
}