Campbell Ritchie wrote:
Junilu Lacar wrote:. . . it's probably best to call nextLine() after a nextInt() or nextByte() to skip past any newlines in the input stream.
DT is right; you may need to clear an empty line before calling newLine(). The problem occurs if you call nextAnythingElse() before newLine(). Many books are not at all clear about newLine().
newLine(), or nextLine()? I don't see newLine in the Scanner docs.
The nextLine method makes sense if you're into Unix-style config and script files. Or Python. Or C++ (and post-C++ C). Or SQL. All of these languages typically have some sort of token that indicates that the rest of the line is a comment and should be ignored.
For example:
In each of these cases, we have a comment delimiter ("//", "#", ";", "--") which tells the lexical scanner to skip (ignore) the rest of the line. So if you're scanning a line and see a comment delimiter, call nextLine() and you're now reading to scan the next line of input - if there is one.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.