public static void main(String[] args) {
System.out.println("Input filename: ");
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
while (input.length() == 0){
System.out.println("Please enter names: ");
String names = sc.nextLine();
}
}
如果不再输入NAMES,如何使程序结束?
答案 0 :(得分:0)
while(input.length() == 0){ // use length() method
System.out.println("Please enter names: ");
String names = sc.nextLine(); //Same scanner but read names to enter into an array
}
}