Read an int from the command line

suggest change
import java.util.Scanner;

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

If you want to read an int from the console, just use this snippet. First of all, you have to create a Scanner object that listens to System.in, which is standard input. After that, with the help of the Scanner object, you read the first int that the user types and store it in the variable number. Now you can do whatever you want with that stored int.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents