Computer Science, asked by T4Talent, 1 year ago

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

Answers

Answered by tiara5
7

Ans. next() read a single token i.e. all characters from the current position till a whitespace or tab or new line is encountered.
nextLine() reads an entire line i.e. all characters from the current position till a new line is encountered.


Answered by prathamesh1855
5
Hey!

next() and nextLine() methods are associated with Scanner and is used for getting String inputs. Their differences are.

next() can read the input only till the space. It can't 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.

Hope It Helps.☺️
Similar questions