这是您的小例子
如何在一行中扫描3个变量就像我有3个名为(x,y和z)的int变量我想在一行中输入三个]
我可以这样输入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[2];
int a;
int b;
System.out.print("Please enter two integers: ");
input = in.readLine().split(" ");
a = Integer.parseInt(input[0]);
b = Integer.parseInt(input[1]);
System.out.println("You input: " + a + " and " + b);
}
这是您的小例子