I'm simply want to get a valid int
value for age
But when user enters an string, why i cant get an int again?
Here is my code:
public static void getAge() throws InputMismatchException {
System.out.print("Enter Your age: ");
try {
age = in.nextInt();
} catch (InputMismatchException imme) {
System.out.println("enter correct value for age:");
in.nextInt(); // why this not works?
}
}
Enter Your age: hh
enter correct value for age:
Exception in thread "main" java.util.InputMismatchException
I want to request to enter a valid int value until a valid input enters.