Method used to take a string as input in Java?

12. Method used to take a string as input in Java?

  1. next()
  2. nextLine()
  3. Both A. and B.
  4. None of these

Answer: B) Both A. and B.

Explanation:

The next() method can read the input only till the space. It can't read two words separated by space, while the nextLine() reads input including space between the words (that is, it reads till the end of line \n).

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.