English

What is the Difference Between the Scanner Class Functions Nextq and Nextline()? - Computer Applications

Advertisements
Advertisements

Question

What is the difference between the Scanner class functions next () and nextLine()?

Distinguish Between
Short Note

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?
2016-2017 (March) Set 1
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×