Im trying to give the user the opportunity to repeat an input after introducing something that has produced an error but something is not working because once the err i
When you enter a non-integer the Scanner
call to nextInt()
doesn't consume the non-integer. You need to call keyboard.next()
(or keyboard.nextLine()
) to consume it. Something like,
try {
dim = keyboard.nextInt();
} catch (Exception e) {
System.out.printf("%s is not an integer.%n", keyboard.next());
err = 1;
}