Search code examples
javamethodsprogram-entry-pointexit

What is the correct format for the System.exit() method?


I believe I'm not formatting the System.exit() method properly. This is how its formatted in my program:

  else if (input==6){
     System.exit();
  }

Is this correct syntax?


Solution

  • System.exit(int) takes an integer argument, but otherwise you can call it to terminate your program.

    Why do you want to call your main() method again? It is normally the static entry point to your program. If there's some code you wish to repeat, I'd suggest putting this in its own method and calling that (from main() and your code in the question).