Web Analytics Made Easy -
StatCounter using a while loop to display a menu - CodingForum


No announcement yet.

using a while loop to display a menu

  • Filter
  • Time
  • Show
Clear All
new posts

  • using a while loop to display a menu

    ok so my program displays a menu with options 1-8 and the user types 1-8 to do something
    when the user is done with whatever option they choose, the menu needs to be displayed back to the user

    i cant get the while loop to redisplay the menu after the user completes an option (i wouldve used a method to redisplay the menu, but my teacher wants us to use a while loop)

    im testing it if the user types 1 so far
    the program just ends, ie it doesnt take me back to the menu when i decrement display or set it back to 0
    im guessing its the switch statements fault?

    heres what i have so far:
    import java.util.Scanner;
    public class assignment1
    	public static void main (String[] args)
    	int display = 0;
    	int option;
    	Scanner keyboard = new Scanner(System.in);
    	while (display < 1)
    		System.out.println("*\t\t\t Array Menu \t\t\t*");
    		System.out.println("*\t\t\t\t\t\t\t* ");
    		System.out.println("*\t1.  Load the values in 'A' Array\t\t*");
    		System.out.println("*\t2.  Add all the elements of 'A' array\t\t*");
    		System.out.println("*\t3.  Find maximum value in 'A' array\t\t*");
    		System.out.println("*\t4.  Find minimum value in 'A' array\t\t*");
    		System.out.println("*\t5.  Transpose 'A' array to 'B' array\t\t*");
    		System.out.println("*\t6.  Display contents of 'A' - Original Array\t*");
    		System.out.println("*\t7.  Display contents of 'B' - Transpose Array\t*");
    		System.out.println("*\t8.  Exit\t\t\t\t\t*");
    	System.out.println("Please select an option");
    	option = keyboard.nextInt();
    	switch (option)
    		case 1:
    			System.out.println("You have selected Option 1 - Load 'A' array");
    			display = 0;
    		case 2:
    			System.out.println("You have selected Option 2 - Add all the elements of 'A' array");
    		case 3:
    			System.out.println("You have selected Option 3 - Find maximum value in 'A' array");
    		case 4:
    			System.out.println("You have selected Option 4 - Find minimum vlaue in 'A' array");
    		case 5:
    			System.out.println("You have selected Option 5 - Transpose 'A' array to 'B' array");
    		case 6:
    			System.out.println("You have selected Option 6 - Display contents of 'A' - Original Array");
    		case 7:
    			System.out.println("You have selected Option 7 - Display contents of 'B' - Transpose Array");
    		case 8:
    			System.out.println("You have selected Option 8 - Exit");
    			System.out.println("Thanks for using Array program - Good Bye!");
    			System.out.println("Select option 1-8");

  • #2
    nevermind, i figured it out, everything had to be inside the while loop