Java Tutorial · Chapter 6 of 12
Java Input
Read input with Scanner.
Import java.util.Scanner, create a Scanner, then call nextLine() or nextInt().
Prompt first, then read. This keeps console programs user-friendly.
Scanner sample
Try it Yourself »
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = input.nextLine();
System.out.print("Enter your age: ");
int age = input.nextInt();
System.out.println("Hello " + name + ", you are " + age + " years old.");
}
}
Classroom Tips
- Provide Console Input in CoderKiosk for interactive programs.