This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Yes, System.exit(0) would end the program. But... I wouldn't make 2 the default case. If you want the user to exit when explicitly selecting '2', then making all but '1' the default case would mean the program would exit if the user selected '3', or '4', or any value other than '1', which seems to go against what you wanted to do. Anywho, that's my last 2 cents for today.
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
I think that System.exit() should rarely be used to end your program. A better way is to ensure that all your threads have finished (in a single-threaded program, this just means allowing main() to return). There are a number of reasons for this: -
System.exit() causes an immediate exit. It does not take account of the state of other threads; they will all be forced to exit immediately.
A method with System.exit() is more difficult to re-use in another application.
The compiler does not realise that flow cannot go beyond a System.exit() call, and hence its ability to check whether you have unreachable code, missing "return", or suchlike, is compromised.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
In addition, as a point of enlightenment, all "break" does is literally break out of the switch block... it has nothing to do with actually terminating your program. You can also use it in loops and so forth.