Hi am new to java programming and I am trying to understand while loops. I haven't used it in the code below but I have an assignment that requires me to. What I want the program to do is simply re prompt the user to enter a menu option 1 to 5 when the code in the switch statement executes based on the user input. I am unsure where to put the while loop in the code and also what to write inside of it. Can someonme please help me with the program I am to create? It also requires me to use a switch statement to evalute the user input. All comments would be appreciated!
import java.util.Scanner;
public class Student_Grade {
public static void main(String[] args) {
get_method();
}
public static void get_method() {
int num;
Scanner menu = new Scanner(System.in);
System.out.println("Please Enter menu 1 and 5 and 0 to exit");
switch (num = menu.nextInt()) {
case 1:
System.out.println("You entered menu option 1");
break;
case 2:
System.out.println("you entered menu option 2");
break;
case 3:
System.out.println("you entered menu option 3");
break;
case 4:
System.out.println("you entered menu option 4");
break;
case 5:
System.out.println("you entered menu option 3");
break;
default:
System.out.println("You entered an invalid option");
break;
}
}
}