Skip to content
Advertisement

java for loop early termination

This is the first half of my java program- to input certain values. I noticed that the first ‘for loop’which takes in values of the answer key is getting terminated after 2 or 3 iterations instead of the expected 5, and I have, so far, had no luck in figuring out why. Any help would be appreciated, thanks!

JavaScript

Advertisement

Answer

BufferedReader.read() method reads one character at a time so what will happen in your case that it will read the empty space or the enter when you are giving input on a new line try giving answer key input on a single line without spaces.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement