I know this exception is not correct because I get that long java.util.InputMismatchException error. The program still allows the user to re-enter but I obviously don't want the long error. What's the actual way to do it?
You never need to catch an InputMismatchException because, as Rob Spoor points out, you can always avoid it. There should be no need to check hasNext() if you use System.in because you should never close a reader or scanner pointing to System.in.
Never use == true or == false, which are poor style and very error‑prone. It's while (flag)... or while (!flag)...
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad: