import java.util.Scanner;
public class ReadIntegerFromStdin {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int num = scanner.nextInt();
System.out.println("You entered: " + num);
}
}
Enter an integer: 18
You entered: 18Scanner object that reads from the standard input (System.in). Then, we use the nextInt() method of the Scanner class to read an integer value entered by the user. println() method of the System.out object.