用Scanner包
①导包
import java.util.Scanner;
②创建对象
Scanner sc = new Scanner(System.in);
③接收数据
int i = sc.nextInt();
import java.util.Scanner; public class demo { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("请输入一个数字x:"); int x = sc.nextInt(); System.out.println("x^2:" + x * x); } }
结果:
请输入一个数字x: 8 x^2:64