try-catch InputMismatchException in a while loop
I've been trying to make this program check whether if the user enters an integer or non integer when they enter a number to be checked whether it's prime or not. But whenever I enter a string, it keeps repeating the error message "Not a number or an integer" instead of taking the users input again.
Here's the try-catch block in the while loop:
while (true){
try{
System.out.print("Please enter a number: ");
int prime = input.nextInt();
break;
}catch (InputMismatchException IME){
System.out.println("\nNot a number or an integer!\n");
continue;
}
}
any help? thanks.