在一行中扫描3个int变量[重复]

问题描述 投票:-1回答:1

如何在一行中扫描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); 
} 
    
java int
1个回答
0
投票

这是您的小例子

© www.soinside.com 2019 - 2024. All rights reserved.