ループ内で Scanner(System.in) を呼び出しているようです。ループの先頭または前に配置してみてください。そのため、テストは機能し、作業は機能しません。
Is this table a simple table? Please check document to confirm, If YES please Enter Y If NO please Enter N
y
Is this table a simple table? Please check document to confirm, If YES please Enter Y If NO please Enter N
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1585)
at ScannerIssue.main(ScannerIssue.java:11)
..
while(true){
System.out.print("Is this table a simple table? Please check document to confirm, If YES please Enter Y If NO please Enter N \n");
Scanner fileS = new Scanner(System.in);
String input = fileS.nextLine();
input = input.trim();
input = input.toLowerCase();
// tableCount ++;
fileS.close();
}
上記のコードは、Move the Scanner fileS = new Scanner(System.in); エラーを引き起こしています。メソッドまたはクラスのスコープの先頭まで。
次のようなものを使用できます。
Scanner fileS = new Scanner(System.in); //moved out of the loop
while (true) {
System.out
.print("Is this table a simple table? Please check document to confirm, If YES please Enter Y If NO please Enter N \n");
String input = fileS.nextLine();
input = input.trim();
input = input.toLowerCase();
// tableCount ++;
if ("n".equalsIgnoreCase(input)) {
break;
}
}
fileS.close(); //moved out of the loop
System.out.println("Good bye!");
}
結果は次のようになります。
Is this table a simple table? Please check document to confirm, If YES please Enter Y If NO please Enter N
Y
Is this table a simple table? Please check document to confirm, If YES please Enter Y If NO please Enter N
A
Is this table a simple table? Please check document to confirm, If YES please Enter Y If NO please Enter N
N
Good bye!