Put a load of print statements into your code, printing the values of the key variables at each stage so you can see where it's going wrong.
JamesCherrill
... trying to help
8,668 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,479
Skill Endorsements: 33
You are probably having a problem with the Scanner class. Scanner methods can be tricky. The Scanner buffers input and can block waiting for input.
For example if you enter: A word to the wise <PRESS ENTER>
and use next() only "A" is read, and "word to the wise" is left in the buffer.
Your next attempt to get something from Scanner will be to get "word".
nextInt() will fail here.
To clear the buffer, use the nextLine() method.
To test if the next token is an int, use the hasNextInt() method.
Try calling the nextLine() method to clear the lineend from the buffer after using the nextInt() method.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Question Answered as of 1 Year Ago by
JamesCherrill,
NormR1
and
devninja