This is my loop. It repeats endlessly if a non-int is entered. From what I can see, it seems like the exception isn’t cleared on the next run of the loop. Or because it takes the previous input and assigns it to menuChoice. How can I fix this?
while(!console.hasNextInt())
{
try {
menuChoice = console.nextInt();
} catch(InputMismatchException e) {
System.out.println("The selection you made is invalid.");
}
}
don’t check for an int in the while loop, check for any input token: