Skip to content
Sharp

Core Java · interview question

You need to read a user's input for a product name in a console application. Which Scanner method should you use?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaconsole-input-and-output
Choose one answer
Answer and explanation

Correct answer

B. NextLine()

Why

The 'nextLine()' method of the Scanner class reads an entire line of input, including spaces, which is suitable for reading a product name that may contain multiple words.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →