# Java Program to display the integer number entered by user

Here we are explaining how to write a java program to read an integer number from the user and print it. In java, we can read an integer number from the user by using the scanner class object.

## What is Scanner class in java?

Scanner class is a java class in java. util package. For using the Scanner class we have to import the java. util package. To read an integer number from the user we have to use the nextInt() function of the Scanner class in java. an example is shown below.

`Scanner scan = new Scanner(System.in);`
`System.out.println("Enter the number: ");`

`int num = sc.nextInt();`

Here first we create an object of the scanner class as a scan.Then read the integer number as sc.nextInt();

## How to implement the java program to read an integer number from the user?

First, we have to declare the class ReadNum.Create an object of the scanner class as sc. Then read an integer number from the user using nextInt() method into the variable a.Then close the scanner class object as sc.close(). By using `System.out.println()` function display the integer number entered by the user as a.

## ALGORITHM

STEP 1: Declare the class ReadNum with a public modifier.

STEP 2: Open the main() to start the program, Java program execution starts with the main()

STEP 3: Create an object of the scanner class as sc.

STEP 4: Read a number from the user into the variable a.

STEP 5: Close the scanner class object.

STEP 6: Display the number a by using `System.out.println()`.

## Java Source Code

```                                          ```import java.util.Scanner;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");

int a = sc.nextInt();

sc.close();

System.out.println("The number you entered is: "+a);
}
}```
```

## OUTPUT

```Enter the number: 100
The number you entered is: 100```
VIEW ALL
VIEW ALL
VIEW ALL
{"ft_lang_label":"__label__en","ft_lang_prob":0.7681185,"math_prob":0.73636216,"size":1653,"snap":"2022-05-2022-21","text_gpt3_token_len":372,"char_repetition_ratio":0.16676773,"word_repetition_ratio":0.11231884,"special_character_ratio":0.2444041,"punctuation_ratio":0.17222223,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.957594,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-21T06:16:06Z\",\"WARC-Record-ID\":\"<urn:uuid:7ce55d0c-c40a-4b46-ae06-c80d93bd8483>\",\"Content-Length\":\"103527\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e2b5ccef-298b-461c-ba7f-19c8881921ba>\",\"WARC-Concurrent-To\":\"<urn:uuid:02a0936a-0e7b-4871-ae56-4948a527f9c5>\",\"WARC-IP-Address\":\"138.197.210.150\",\"WARC-Target-URI\":\"https://learnetutorials.com/java/programs/read-and-display-number-given-by-user\",\"WARC-Payload-Digest\":\"sha1:TSQSJJOLTL6DYYDF5VHP3PBSNLBUCS25\",\"WARC-Block-Digest\":\"sha1:OBHHXVVGWMXUWTAK7G3CBI7JLKN24FU7\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662538646.33_warc_CC-MAIN-20220521045616-20220521075616-00698.warc.gz\"}"}