I was reading the API for Java because I had a question on the difference between .nextLine()
and .nextDouble()
. In the API, it says this for .nextLine()
:
"Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line."
Easy enough...it skips the current line you are on and then returns the line you just skipped. But for .nextDouble()
, it says this:
"Scans the next token of the input as a double. This method will throw InputMismatchException if the next token cannot be translated into a valid double value. If the translation is successful, the scanner advances past the input that matched."
So does this mean that .nextDouble()
does not skip to a new line and that it only reads until the end of the double and then stops at the end of the line? This would help me in understanding a program I'm working on now. Thanks guys and gals!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…