• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanner not waiting for input.  RSS feed

 
Adam Miszczak
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I know this is probably a problem with a stupidly easy fix and I'm just not thinking but I've been trying to figure out why the scanner does not wait for input in this code:



Can anyone help me solve this?

Thanks!
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you never invoked you MenuInput method inside main, so it doesn't get executed.

Also note that you have two else blocks that contain same statements. Instead of it, you could put if - else if - else blocks to check your input. Or, if you use JDK 7 you can use switch statement with Strings, so it would be the best approach to use here. And, instead of invoking MenuInput again if the user does not provide valid input, you should put everything inside while, that will prompt the user for input until valid one is entered.

Edit: Method names don't start with capital letter in Java.
 
Adam Miszczak
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!