Java Scanner & Interactive Input
The `Scanner` class from the `java.util` package is the standard tool for reading user input in console applications. It parses primitive types and strings using regular expressions from `System.in`.
"Scanner is like an attentive stenographer listening to System.in. When you ask for an integer with .nextInt(), it listens until a number is typed and delivers it into your variable."
Deep Dive: How It Works
Import required: `import java.util.Scanner;` at the top of your file.
Instantiation: `Scanner scanner = new Scanner(System.in);`
Methods: `.nextLine()` (reads full line text), `.next()` (reads single word), `.nextInt()`, `.nextDouble()`, `.nextBoolean()`.
Closing: Call `scanner.close()` when finished to release system resources.
Syntax Blueprint
import java.util.Scanner; Scanner sc = new Scanner(System.in); String name = sc.nextLine(); int age = sc.nextInt(); sc.close();
Always import Scanner from java.util and instantiate with System.in.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Calling nextLine() immediately after nextInt()Why it happens: nextInt() consumes the number but leaves the newline character in the buffer.
How to fix: Call an extra scanner.nextLine() to consume the leftover newline before reading text.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Read and double an input number
Read the integer from the scanner.
Multiply it by 2 and print "Double: " + (num * 2).
Finished reading and practicing?
Mark this lesson as completed to update your course progress.