Roy Poh wrote:Hi so my program works fine but there are some exceptions which i am not sure how to deal with, like how do i make it such that when the choice is not an integer but a character, it will loop back to the menu. I am new to java so it would be great if you could guide me
Winston Gutkowski wrote:You might also want to look at the Console class (java.io.Console) because it contains some nice methods that combine the business of taking input and displaying a prompt message.
Pawel Pawlowicz wrote:If you choose to use Console class, be careful. Do not run your program with an IDE because you might get NullPointerException.
Pawel Pawlowicz wrote:It's because some IDEs run their processes in the background and they might not have a console attached to them.
So System.concole() might return null.
Winston Gutkowski wrote:In which case you may not be able to use it - a big pity, because it's a very nice and simple class - so you're stuck with the accursed Scanner.
Pawel Pawlowicz wrote:But OP is just learning Java, right? So he doesn't use any IDE, right? And he compiles and runs his program from console, right ?