There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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 ?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Consider Paul's rocket mass heater. |