read int java

Solutions on MaxInterview for read int java by the best coders in the world

showing results for - "read int java"
Vincent
26 Sep 2020
1import java.util.Scanner;
2
3public class Demo {
4
5    public static void main(String[] args) {
6
7        /* This reads the input provided by user
8         * using keyboard
9         */
10        Scanner scan = new Scanner(System.in);
11        System.out.print("Enter any number: ");
12
13        // This method reads the number provided using keyboard
14        int num = scan.nextInt();
15
16        // Closing Scanner after the use
17        scan.close();
18        
19        // Displaying the number 
20        System.out.println("The number entered by user: "+num);
21    }
22}