ICSE Class 10 Computer Applications Question 12 of 32

Input in Java — Question 12

Back to all questions
12
Question

Question 12

Distinguish between the following:

i. next() and nextLine()

Answer
next()nextLine()
It reads the input only till the next complete token until the delimiter is encountered.It reads the input till the end of line so it can read a full sentence including spaces.
It places the cursor in the same line after reading the input.It places the cursor in the next line after reading the input.

ii. next() and next().charAt(0)

next()next().charAt(0)
It reads the input only till the next complete token until the delimiter is encountered.It reads the complete token and then the first character is returned using the charAt(0) method.
It returns the read data as a String value.It returns the read data as a char value.

iii. next() and hasNext()

next()hasNext()
It reads the input till the next complete token until the delimiter is encountered.It checks if the Scanner has another token in its input.
It returns a String value.It returns a boolean value.

iv. hasNext() and hasNextLine()

hasNext()hasNextLine()
Returns true if the Scanner object has another token in its input.Returns true if there is another line in the input of the Scanner object.