How to read an integer value from standard input?

Question:
How to read integer value from the standard input?

Answer:
Use the scanner class along with its nextInt() method.

Code:
import java.util.Scanner;
 
public class ReadInt {
 
   public static void main(String[] args) {
 
      Scanner sc = new Scanner(System.in);
 
      System.out.print("Enter Integer: ");
      int i = sc.nextInt();
      System.out.println("You entered: " + i);
   }
}

Output:
$ java ReadInt 
Enter Integer: 1234
You entered: 1234