Java Language Read an int from the command line


import java.util.Scanner;

Scanner s = new Scanner(;
int number = s.nextInt();

If you want to read an int from the command line, just use this snippet. First of all, you have to create a Scanner object, that listens to, which is by default the Command Line, when you start the program from the command line. After that, with the help of the Scanner object, you read the first int that the user passes into the command line and store it in the variable number. Now you can do whatever you want with that stored int.