Why in.nextLine() and in.next() is used in scanner class
Plz answer in points
Answers
next() is used to acceptance token as string from scanner object
When a line of text is given as input to the scanner object it will receive first token only
The rest of the token can be obtained by nextLine().
Example good so here if you use next() only "g" will come out....n of u use nectLine() "good" will come out
nextLine() is to include a complete sentence with spaces
Please mark brainliest
Once again thanks to both of u for helping
in.nexLine() is used to accept the entire String sentence avialable to the scanner object, before a line break, and stored in the string variable.
in.next() however accepts only the next token....i.e. only the word avialable( the characters avialable to thr scanner object in before a delimiter(by default a whitespace and linebreak are delimiters for scanner class)occurs).
Consider this example:-
If you Enter: Hi I amRahul
using:str = in.nextLine(); the entire sentence is stored in str.
using:str1= in.next();only the first word (here Hi) enters into str1.
Therefore, Output:
str= Hi I am Rahul
str1= Hi