Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package switchstatments;
- import java.util.Scanner;
- /**
- * @author Kitty
- */
- public class SwitchStatments {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // introduces the keyboard object for the Scanner class
- Scanner keyboard = new Scanner(System.in);
- // introduces the boolean that closes the menu and the integer that holds the value of the menu number
- boolean redo = true;
- int menuNum = 0;
- // start of the do while loop
- do {
- // asks user for input
- System.out.println("What menu do you want to go to");
- // sets the value of the menu number to the value input by the user
- menuNum = keyboard.nextInt();
- // start of the switch statement with the integer menuNum
- switch (menuNum){
- // checks if the menuNum is 0
- case 0:
- // makes the loop variable false and exits the program
- redo = false;
- break;
- // checks if the menuNum is 1
- case 1:
- // sets the balue of redo to true so it will loop
- redo = true;
- break;
- // checks if the menuNum is 2
- case 2:
- // sets the balue of redo to true so it will loop
- redo = true;
- break;
- }
- // tells the user the menu they are on
- System.out.println("You are in menu "+ menuNum);
- // if the value of redo is true then it will loop
- } while (redo);
- // exiting message
- System.out.println("You are exiting the program. Goodbye.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement