Skip to content
Advertisement

How to do a switch menu in java with do while

Good day!

This is my switch menu for a project in java!

When I put a diferent letter (letter that it´s not in the switch) I get this error message, and when I try one of the correct letter I get the same error message again:

JavaScript

This is my code:

JavaScript

I tryed with numbers and I got the same error message

Advertisement

Answer

Don’t recreate the scanner each time menu is called. Create it once at start of main and use it, such as:

JavaScript

and in menu:

JavaScript
Advertisement