Basically what's happening is if I input something other than an integer for:
Age = inputVariable.nextInt();
It will give me this error:
java.util.InputMismatchException.
This is what I have so far:
try {
// Get Age
System.out.println("Age: ");
Age = inputVariable.nextInt();
} catch (Exception e) {
Age = 0;
inputVariable.reset();
System.out.println("You have not entered a valid age, please try again.");
Age = inputVariable.nextInt();
System.out.println("Age: ");
}
I've added Age=0 and inputVariable.reset to try and clear it for re-input but it does not work. I just receive the same error once it gets to the second user input for Age.
So can someone tell me how to clear the scanner for another input?
Thanks.


Sign In
Create Account


Back to top









