Scanner in = new Scanner(System.in);
boolean error = true;
while (error) {
try {
System.out.println("Please enter a number: h");
int x = in.nextInt();
error = false;
} catch (InputMismatchException exception) {
System.out.println("Oops! That was no valid number. Try again...");
in.nextLine();
}
} |