我可以这样输入7 21 35
int x = 7;
int y = 21;
int z = 35;
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
System.out.printf("%2d, %2d, %2d\n", x, y, z);
[我在C ++中发现了一些东西,它们的代码是这样的(scanf(“%lf%lf%lf”,&x,&y,&z);)]
您如何在一行中扫描3个变量,就像我有3个名为(x,y和z)的int变量一样,我想在一行中输入三个变量,我可以像这样输入7 21 35
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] input = new String[3];
int x;
int y;
int z;
System.out.print("Please enter Three integers: ");
input = in.readLine().split(" ");
x = Integer.parseInt(input[0]);
y = Integer.parseInt(input[1]);
z = Integer.parseInt(input[2]);
System.out.println("You input: " + x + ", " + y + " and " + z);
}