Hint 3
Use a Boolean variable to indicate when the user has entered a valid number.
Add a while loop to the program that includes the code where the input is read and the try-catch
statement. The loop should terminate when the Boolean variable has value true. So, what should the initial
value for the variable be? Where should your code change the value of the Boolean variable to true? Remember
that if an exception was thrown when invoking parseInt
then any code between this statement
and the catch
statement will be ignored; so if an exception is not thrown any code between
the invocation to parseInt
and catch
will be executed (is this a good place to
change the value of the variable?).