Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

stupid jave bah!

Options
  • 26-03-2002 10:25pm
    #1
    Registered Users Posts: 11,397 ✭✭✭✭


    I'm too tired to think straight anyway easy question:

    I have a program with 4 choices, the forth choice is to exit the program will "while (choice != 4)" exit the program if 4 is pressed or do is there some command?
    while (choice != 4)
     {
    
         System.out.println("\n\n1.Insert a number");
         System.out.println("2.Remove a number");
         System.out.println("3.Display the Array");
         System.out.println("4.Exit");
         choice = Integer.parseInt(kbd.readLine());
    

    I haven't actually got any of the rest of it to work yet either, so if anyone's in the mood to write it i won't say no ;)

    And how do you remove a number from teh array?

    tanx in advance.


Comments

  • Registered Users Posts: 1,481 ✭✭✭satchmo


    The best way to do it is probably:
    int choice=-1;
    do{
        switch(choice){
            case 1:insertNumber();choice=-1;break;
            case 2:removeNumber();choice=-1;break;
            case 3:displayArray();choice=-1;break;
            case 4:System.exit(0);choice=-1;break;
            default:
            System.out.println("\n\n1.Insert a number");
            System.out.println("2.Remove a number");
            System.out.println("3.Display the Array");
            System.out.println("4.Exit");
            System.out.print(">");
            break;
        }
    }while((choice=Integer.parseInt(kbd.readLine()))!=4);
    

    or something similar. You'll have to write those methods for 1-3, but you get the idea.

    Sorry if this makes no sense, I'm quite drunk.


Advertisement