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)...