通过扫描仪类获取输入
import java.util.Scanner; public class ScannerApp /* NowJava.com */ { static Scanner sc = new Scanner(System.in); public static void main(String[] args){ System.out.print("Enter an integer: "); int x = sc.nextInt(); System.out.println("You entered " + x + "."); } }