Hello Guys, I am facing problem while i am create menu system using swtich statement. I have 3 level of menu but don't know how to go back to main switch Statement. For Example currently I am in 2nd level of switch but how to go in main(outer) switch. Please its Urgent. Thanxxx in advance :)

Recommended Answers

All 2 Replies

System.out.println("******Welcome To Main Menu*******");

System.out.println("******Welcome To Main Menu*******");   
        System.out.println("\n");
        System.out.println("\t------------------------------------");
        System.out.println("\t|Commands: 1 - Manage Item         |");
        System.out.println("\t|          2 - Make New Sale       |");
        System.out.println("\t|          3 - Make Payemt         |");
        System.out.println("\t|          4 - Print Report        |");
        System.out.println("\t|          5 - Exit                |");
        System.out.println("\t------------------------------------");
        System.out.println("");
        int a=in.nextInt();

        switch(a)
        {
            case 1:
        System.out.println("\t------------------------------------");
        System.out.println("\t|Commands: 1 - Add New Item         |");
        System.out.println("\t|          2 - Find Item            |");
        System.out.println("\t|          3 - Modify Item          |");
        System.out.println("\t|          4 - Remove Item          |");
        System.out.println("\t|          5 - Go Back              |");
        System.out.println("\t------------------------------------");
        System.out.println("");
                int b=in.nextInt();
                switch(b)
                {
                    case 1:
                        im.AddNewItem();
                        break;
                    case 5:
                      //from here I want to go back to main switch  
                }
                break;
            case 5:

        }

create methods:

printMainMenu();
printSubMenu1();
...

and on

case 5:
  --counter;
    if ( counter == 0 ) printMainMenu();

...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.