Recall & Review
beginner
What class in Java is commonly used to read string input from the user?The <strong>Scanner</strong> class is commonly used to read string input from the user in Java.Click to reveal answer
beginner
How do you create a Scanner object to read input from the keyboard?
You create it with:
Scanner scanner = new Scanner(System.in); This connects the Scanner to the keyboard input.Click to reveal answer
beginner
Which Scanner method reads a whole line of text including spaces?
The method
nextLine() reads the entire line of input including spaces until the user presses Enter.Click to reveal answer
beginner
What happens if you use
next() instead of nextLine() to read a string?next() reads only the next word (up to the first space), not the whole line.Click to reveal answer
intermediate
Why should you close the Scanner object after use?
Closing the Scanner with
scanner.close(); frees system resources and avoids resource leaks.Click to reveal answer
Which method reads a full line of user input including spaces?
✗ Incorrect
nextLine() reads the entire line including spaces until Enter is pressed.How do you create a Scanner to read from the keyboard?
✗ Incorrect
You must use
System.in to read input from the keyboard.What does
next() method read from input?✗ Incorrect
next() reads the next token (word) separated by whitespace.Why is it important to close a Scanner object?
✗ Incorrect
Closing Scanner frees resources and prevents resource leaks.
Which import statement is needed to use Scanner?
✗ Incorrect
Scanner is part of the java.util package.
Explain how to read a full line of string input from the user in Java.
Think about connecting Scanner to keyboard and reading the entire line.
You got /3 concepts.
What is the difference between next() and nextLine() methods in Scanner?
Consider how spaces affect what each method reads.
You got /4 concepts.