You are viewing a single comment's thread. Return to all comments →
I've done some research on this.
Basically, hasNext() will block until Standard input (stdin) is closed.
So when you run in an IDE, this loop never ends if you never kill stdin.
It looks like on Hackerrank, at the end of the file, stdin is being closed thus it ends.
You can also have some kind of 'END_OF_FILE' token to indicate end of input.