Edward Mallia wrote:What exactly does the "break" do . . .
It exits the
switch statement. Always write
break; after every
case XXX: or
default: unless you actually want fall‑through. In which case wite a comment saying the fall‑through is intentional.
The reason option 3 works is that you are exiting the program altogether. I don't think it is a good idea to use
System.exit(). It might not cause any problems in a simple app like yours, but as soon as you start multi‑threading,
System.exit() can do no end of harm because it can terminate programs which haven't finished their tasks.
Only use \n and \r if somebody has told you they want a particular line end. If you need empty lines before the start of the printout, write
System.out.printf("%nOne line%nSecond line%n"); or similar.
Your methods are much too long; they should be divided into much smaller methods.
Remove the keyword
static from your vocabulary. That takes you out of the realms of object‑oriented programming. You should have written a VendingMachine class, a Product class, and probably a few more classes.