×

java · level 1 · unit 2 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A lets your program ask a question.

So far your programs only talk. To listen, they need a Scanner, a tool that reads : whatever the person types. Borrow it with on the very first line.

Then make one: Scanner keyboard = new Scanner(System.in);. new builds a fresh tool, and System.in means the keyboard. We keep it in a box called keyboard.

keyboard.nextLine() waits while the person types an answer and presses Enter. It gives back what they typed as a String, so store it in a box.

Ask with print, not println, so the answer is typed on the same line as the question.