I am working on some code and using a Switch statement with a Scanner to get user input.The input needs to be an integer and if it isn't then i want
to catch the InputMismatchException and allow the user to go back to the options menu and try again.
if you look at the catch block i wrote in the error i get, but i thought this is how one should discard the last entry?? How else can i do that?
Important note: you can prevent the exception. Scanner has methods for checking what's available next. Instead of catching the exception you can test the result of hasNextInt(). Don't forget to consume the input like you're doing now or you'll hit an infinite loop.
Please avoid long lines in code tags; the scrolling makes them difficult to read. For reasons explained here, it is probably a bad idea to use tab characters for indentation; use spaces instead. Get a decent text editor like Notepad++ and it can do the indentation for you.
Thanks for the tipp, i use Eclipse and it does it automatically when i hit enter.I guess it uses tabs not sure.
The link yiou sent i just see a tiny lil brown box , kinda microscopic not sure what it is suppose to be,