What is the Difference Between the Scanner Class Functions Nextq and Nextline()?
Advertisements
Question
What is the difference between the Scanner class functions next () and nextLine()?
Distinguish Between
Short/Brief Note
Advertisements
Solution
next ( ) can read the input only till space. It cannot read two words separated by space.
Also, next( ) places the cursor in the same line after reading the input.
nextLine( ) reads input including space between the words (that is, it reads till the end of line \n). Once the input is read, nextLine( ) positions the cursor in the next line.
shaalaa.com
Is there an error in this question or solution?
