Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OptionMenu {
- public static void main(String [] args){
- Scanner scanner = new Scanner(System.in);
- // Display the menu
- System.out.println("1\t Menu option 1");
- System.out.println("2\t Menu option 2");
- System.out.println("3\t Menu option 3");
- System.out.println("4\t Menu option 4");
- System.out.println();
- System.out.println("Please enter your choice:");
- //Get user's choice
- int choice = scanner.nextInt();
- //Display the title of the chosen module
- switch (choice) {
- case 1: System.out.println("You choose the 1st menu option.");
- break;
- case 2: System.out.println("You choose the second menu option.");
- break;
- case 3: System.out.println("The third menu option, was the one you chose.");
- break;
- case 4: System.out.println("The forth one from the top was chosen.");
- break;
- default: System.out.println("Invalid choice");
- }//end of switch
- }//end of the main method
- }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement