Reading Input from the Console
Quickly capture user input from the console in your Java applications using the Scanner class.
Quickly capture user input from the console in your Java applications using the Scanner class.
import java.util.Scanner;
public class ConsoleInput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = scanner.nextInt();
System.out.println("You entered: " + number);
scanner.close();
}
}