how to get any number from user in java

Solutions on MaxInterview for how to get any number from user in java by the best coders in the world

showing results for - "how to get any number from user in java"
Juan Sebastián
06 Apr 2018
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}