Here's a simple Java program that reads input from the console using the `Scanner` class:
import java.util.Scanner;
public class ConsoleInput {
public static void main(String[] args) {
// Create a Scanner object to read input from the console
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter their name
System.out.print("Enter your name: ");
// Read the input from the console
String name = scanner.nextLine();
// Prompt the user to enter their age
System.out.print("Enter your age: ");
// Read the input from the console
int age = scanner.nextInt();
// Display the input back to the user
System.out.println("Hello, " + name + "! You are " + age + " years old.");
// Close the scanner
scanner.close();
}
}
This program prompts the user to enter their name and age, reads the input from the console using the `Scanner.nextLine()` and `Scanner.nextInt()` methods respectively, and then displays the input back to the user. Finally, it closes the `Scanner` object to release any resources associated with it.