One of the simplest ways is to use a Scanner
object as follows:
(最简单的方法之一是使用Scanner
对象,如下所示:)
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();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…