Java 用户输入以空格分隔的整数

Java 用户输入以空格分隔的整数,java,Java,我的代码可以工作,但当用户将a、b和c的值放入另一行时,它会打印出来。我希望一次输入所有值,并用空格分隔(例如10 11 13),然后进行计算。如何将所有这些输入放在一行上,仅用空格分隔,然后进行计算?扫描仪按开箱即用的空格进行定界。下面的代码应该可以帮助您找到所需的内容 int a,b,c,d; system.out.println("enter number"); a=input.nextInt(); system.out.println("enter number"); b=inp

我的代码可以工作,但当用户将a、b和c的值放入另一行时,它会打印出来。我希望一次输入所有值,并用空格分隔(例如10 11 13),然后进行计算。如何将所有这些输入放在一行上,仅用空格分隔,然后进行计算?

扫描仪按开箱即用的空格进行定界。下面的代码应该可以帮助您找到所需的内容

int a,b,c,d;

system.out.println("enter number");

a=input.nextInt();

system.out.println("enter number");

b=input.nextInt();

system.out.println("enter number");

c=input.nextInt();

d=(a*b)+c;

system.out.println("the total number is" + d);
控制台应显示:

public static void main(String[] args) {
    Scanner myScanner = new Scanner(System.in);
    System.out
            .println("Please enter three integers separated by white space.");
    int myInt1 = myScanner.nextInt();
    int myInt2 = myScanner.nextInt();
    int myInt3 = myScanner.nextInt();
    int mySum = myInt1 + myInt2 + myInt3;

    System.out.println("The sum of " + myInt1 + " + " + myInt2 + " + "
            + myInt3 + " = " + mySum);

    myScanner.close();
}

扫描仪按开箱即用的空间进行定界。下面的代码应该可以帮助您找到所需的内容

int a,b,c,d;

system.out.println("enter number");

a=input.nextInt();

system.out.println("enter number");

b=input.nextInt();

system.out.println("enter number");

c=input.nextInt();

d=(a*b)+c;

system.out.println("the total number is" + d);
控制台应显示:

public static void main(String[] args) {
    Scanner myScanner = new Scanner(System.in);
    System.out
            .println("Please enter three integers separated by white space.");
    int myInt1 = myScanner.nextInt();
    int myInt2 = myScanner.nextInt();
    int myInt3 = myScanner.nextInt();
    int mySum = myInt1 + myInt2 + myInt3;

    System.out.println("The sum of " + myInt1 + " + " + myInt2 + " + "
            + myInt3 + " = " + mySum);

    myScanner.close();
}

我看你的代码没有任何问题。我认为您只需要删除额外的
sysout
,它应该可以正常工作

请尝试以下代码段:

Please enter three integers separated by white space.
1 30 45
The sum of 1 + 30 + 45 = 76
输出:

int a,b,c,d;
Scanner input = new Scanner(System.in);
System.out.println("Enter 3 Numbers (Separated By White-space): ");

a = input.nextInt();
b = input.nextInt();
c = input.nextInt();

d = (a*b)+c;

System.out.println("The Total Number: " + d);

我看你的代码没有任何问题。我认为您只需要删除额外的
sysout
,它应该可以正常工作

请尝试以下代码段:

Please enter three integers separated by white space.
1 30 45
The sum of 1 + 30 + 45 = 76
输出:

int a,b,c,d;
Scanner input = new Scanner(System.in);
System.out.println("Enter 3 Numbers (Separated By White-space): ");

a = input.nextInt();
b = input.nextInt();
c = input.nextInt();

d = (a*b)+c;

System.out.println("The Total Number: " + d);

请包括如何初始化
输入
变量。请包括如何初始化
输入
变量。@Mak Haylu欢迎您!如果您满意,请接受答案。@Mak Haylu欢迎您!如果您满意,请接受答案。