ユーザー入力値が int 値でないかどうかを確認する必要があります。私が知っていることのさまざまな組み合わせを試しましたが、何も得られないか、ランダムなエラーが発生します
例えば:
ユーザーが「adfadf 1324」と入力すると、警告メッセージが表示されます。
私が持っているもの:
// Initialize a Scanner to read input from the command line
Scanner sc = new Scanner(System.in);
int integer, smallest = 0, input;
boolean error = false;
System.out.print("Enter an integer between 1-100: ");
range = sc.nextInt();
if(!sc.hasNextInt()) {
error = true;
System.out.println("Invalid input!");
System.out.print("How many integers shall we compare? (Enter an integer between 1-100: ");
sc.next();
}
while(error) {
for(int ii = 1; ii <= integer; ii++) {
...
} // end for loop
}
System.out.println("The smallest number entered was: " + smallest);
}
}