Input output integer

Java has multiple ways to read input from the console. In this program, we are using the class Scanner to read input from the console.

Output Integer

You can directly print an integer value to the console without specifying its data-type, however, Java also provides a way to print integer data just like in C language.

See also: Java program to print to console

Method nextInt()

The method nextInt() of Scanner class is used to read integer number from the console.

Program

import java.util.Scanner;

public class InputOutputInteger {
    
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter any number : ");

        // Read integer input
        int input = scanner.nextInt();

        // Print integer
        System.out.println("Your entered number : " + input);
    }
}

Output

Enter any number : 100
Your entered number : 100