After you enter "m" and hit the ENTER key, the input stream will contain not just the 'm' character, but also the character(s) corresponding to the ENTER key. Depending on your operating system, this will usually mean that you have an extra '\n' character, or an extra '\r' character, or even an extra "\r\n" sequence of two characters.
As a result, your second read() call will read this extra character off the input stream and return immediately, instead of pausing for user input. One way of fixing this would be to modify your second read() call to look like this:
(P.S.: You may also want to re-consider your placement of your if statements. What happens if the user types 's' or 'p' in response to your first prompt?)
Joined: Nov 23, 2007
Ok, Thank you.
I did what you suggested and it is finally getting there however now it just stops, do I have to put what you suggested in every time I need to prompt for a response?
In resopnse to your P.S., I realize I have much more error checking to do but I am just trying to get my my main questioning part going first.
Kelvin Chenhao Lim
Joined: Oct 20, 2007
Originally posted by Mark Adams: I did what you suggested and it is finally getting there however now it just stops, do I have to put what you suggested in every time I need to prompt for a response?
Yes. To avoid excessive code duplication, you will probably want to wrap this up in a separate utility method, e.g.
which will then allow you to simply get the user's responses using just:
(Note that a more general solution would probably wrap System.in within a InputStreamReader and possibly also a BufferedReader. But the above is likely to suffice for your needs.)