I think you are mistaken trying to validate your meal code inside your main method. A main method is intended for starting your application, and you should restrict your methods to doing one thing. I think you should write yourself a utility class with such methods in. You can find an example
here. You can write another method (in the same utility class) which validates the input is in the required range, (is it 1…5?) and prints an error message on screen. Those two methods call each other, so you are not duplicating code. Remember all members of utility classes are
static.