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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

stupid jave bah!

  • 26-03-2002 9:25pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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