Java Program to Read Integer Value from the Standard Input

To read an integer value from the standard input in Java, we can use the Scanner class from the java.util package. Here's an example :
Program :
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);
    }
}
Output :
Enter an integer: 18
You entered: 18
In this program, we first create a Scanner 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.

Finally, we print out the value of the integer using the println() method of the System.out object.