Back
One of the easiest methods is to use a Scanner object as pursues:
import java.util.Scanner;Scanner reader = new Scanner(System.in); // Reading from System.inSystem.out.println("Enter a number: ");int n = reader.nextInt(); // Scans the next token of the input as an int.//once finishedreader.close();
import java.util.Scanner;
Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Enter a number: ");
int n = reader.nextInt(); // Scans the next token of the input as an int.
//once finished
reader.close();
31k questions
32.8k answers
501 comments
693 users