Advertisement
thotfrnk

individual activity.java

Nov 10th, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.util.Scanner; //importing scanner
  2. public class individual_activity { //program begins
  3.     public static void main(String[] args) {
  4.  
  5.         //Done by: me
  6.  
  7.         Scanner input = new Scanner (System.in);
  8.  
  9.         //declaring variable
  10.  
  11.         int menu;
  12.  
  13.         //letting users input the variable
  14.  
  15.         System.out.println("Enter options 1 to 5 or 0 to exit: ");
  16.         menu = input.nextInt();
  17.  
  18.         while(menu != 0) { //while loop is used as a continuous loop, and it can be exited with 0 is entered.
  19.  
  20.             switch(menu) { //switch statement is used to display the option chosen.
  21.  
  22.                 case 1: System.out.println("You chose option 1.");
  23.                     break;
  24.                 case 2: System.out.println("You chose option 2.");
  25.                     break;
  26.                 case 3: System.out.println("You chose option 3.");
  27.                     break;
  28.                 case 4: System.out.println("You chose option 4.");
  29.                     break;
  30.                 case 5: System.out.println("You chose option 5.");
  31.                     break;
  32.                 default: System.out.println("Invalid Code.");
  33.  
  34.             } //switch statement ends
  35.  
  36.             System.out.println("Enter options 1 to 5 or 0 to exit: ");
  37.             menu = input.nextInt();
  38.  
  39.         } //while loop ends
  40.  
  41.         System.out.println("Thank you for using this menu."); //displays when user enters 0
  42.     }
  43. } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement