Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Scanner console input problem

Started by Halsafar Oct 11, 2005 at 8:23 PM 1 replies 350+ views
Original Post
Halsafar
Halsafar
Not sure wuts going on but it puts my program for a nasty loop. I have a statement like this trapped in a while loop intended to act as a console menu. So the user is suppose to enter a selection. Scanner in = new Scanner(System.in); if (m_in.hasNextInt()) { int iSelection = m_in.nextInt(); } Now, if I enter a "q" for example... The program evaluates hasNextInt() to false without even asking for input for the rest of the life of the program.
n0rmanfreak
n0rmanfreak
hi!

can you please more of that while-loop ? so we can see what variable might get changed...
btw, are you creating that scanner everytime in your loop? that's a bad idea anyway ;)
besides that you might to have to erase the current token in the scanner ...so that the character might not block the scanner for all times ...but i'm not sure about that...just a quick guess.

hope this helps
Lucidquiet
Lucidquiet
Are you trying to make a bufferred line reader?
What is a Scanner?
For that matter what is the difference between in, and m_in?
And if your asking if "q" is an Int then wouldn't that be false?

I think more source code would help.

L-

"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.