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

As basic a java qeustion as you can get!!

Options
  • 04-03-2004 3:42pm
    #1
    Registered Users Posts: 940 ✭✭✭


    How do you end the program??
    I need some one to be able to type 0 and have the program end,

    I serached for it but I only found System.exit and that wont work!!

    Common guys this is the most basic Q out there, help an idiot out will ya??


Comments

  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    you could read in the integer and pass it to system.exit

    int endValue = System.in.readLine();

    System.exit(endValue);

    if endValue is = 0 then this will exit the program, however I have no idea what System.exit() does when you pass any other integer value?

    I suspect your problem was you werent doing System.exit(0) rather just System.exit or something else silly


  • Registered Users Posts: 15,258 ✭✭✭✭Rabies


    in a nut shell....




    //read in number num

    while (num != 0)
    {

    //do what ever you want


    //read number again before end of loop...
    }


  • Registered Users Posts: 940 ✭✭✭LanceStorm


    I was just using

    System.exit();

    I'll give System.exit(0) a shot n see what happens, thanks guys!!


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    While that works, its considered to be "bad style" when compared with using System methods to terminate the process imo


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    I normally let the top level method finish running, and close out a method by doing a return and setting a value to tell the program it is finished (if that is what to do).

    As for the exit code, it is an errorlevel passed back to the system. It would be up to the system to handle it.

    example.
    [b]sample.bat[/b]
    @echo off
    REM Batch file to demontrate error level.
    
    java myApplication
    
    if errorlevel == 1 echo error 1 happened. 
    
    

    So if you did a System.exit(1); it should cause the Echo command to execute.


  • Advertisement
Advertisement