Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用循环求和_Java_Loops_While Loop - Fatal编程技术网

Java 使用循环求和

Java 使用循环求和,java,loops,while-loop,Java,Loops,While Loop,我的目标是:编写一个应用程序,使用while循环从用户那里获取20个输入,并显示所有这些数字的总和 我知道如何进行while循环,但我不知道如何得到所有这些数字的总和(因为变量是相同的)。以下是我到目前为止的情况: Scanner Numb = new Scanner (System.in); int count = 0; while (count<20) { System.out.println("Enter number: "); int numb = Numb.ne

我的目标是:编写一个应用程序,使用while循环从用户那里获取20个输入,并显示所有这些数字的总和

我知道如何进行while循环,但我不知道如何得到所有这些数字的总和(因为变量是相同的)。以下是我到目前为止的情况:

Scanner Numb = new Scanner (System.in); 
int count = 0;
while (count<20) {
    System.out.println("Enter number: ");
    int numb = Numb.nextInt();
    count++;
Scanner Numb=新扫描仪(System.in);
整数计数=0;

虽然(count您需要另一个变量将其添加到while循环外部。

您需要另一个变量将其添加到while循环外部。

您需要另一个变量将其添加到while循环外部。

您需要另一个变量将其添加到while循环外部。

使用公共变量存储嗯

int sum = 0;
int count = 0;
while (count<20) {
    System.out.println("Enter number: ");
    int numb = Numb.nextInt();
    sum = sum+numb;
    count++;
}
System.out.println("sum is "+sum);
int和=0;
整数计数=0;

而(count使用公共变量存储总和

int sum = 0;
int count = 0;
while (count<20) {
    System.out.println("Enter number: ");
    int numb = Numb.nextInt();
    sum = sum+numb;
    count++;
}
System.out.println("sum is "+sum);
int和=0;
整数计数=0;

而(count使用公共变量存储总和

int sum = 0;
int count = 0;
while (count<20) {
    System.out.println("Enter number: ");
    int numb = Numb.nextInt();
    sum = sum+numb;
    count++;
}
System.out.println("sum is "+sum);
int和=0;
整数计数=0;

而(count使用公共变量存储总和

int sum = 0;
int count = 0;
while (count<20) {
    System.out.println("Enter number: ");
    int numb = Numb.nextInt();
    sum = sum+numb;
    count++;
}
System.out.println("sum is "+sum);
int和=0;
整数计数=0;

while(谢谢。我真的很感谢你的帮助。while循环在其他方面看起来很好,对吗?系统允许我时会这样做:)谢谢。我真的很感谢你的帮助。while循环在其他方面看起来很好,对吗?系统允许我时会这样做:)谢谢。我真的很感谢您的帮助。while循环在其他方面看起来很好,对吗?只要系统允许,我就会这样做:)谢谢。我真的很感谢您的帮助。while循环在其他方面看起来很好,对吗?只要系统允许,我就会这样做:)用20个用户输入测试一个程序是一个噩梦。考虑用二十个元素填充一个int数组,包含20个用户输入,然后将数组传递到<代码> GETSUM(I[])。你可以创建测试数据,而不必输入……所有…二十……数字……每个…单…时间……用20个用户输入测试程序是一个噩梦。考虑用二十个元素填充一个int数组,用20个用户输入,然后将数组传递到<代码> GATSUM(I[])你可以创建测试数据,而不必输入……所有…二十……数字……每个…单…时间……用20个用户输入测试程序是一个噩梦。考虑用二十个元素填充一个int数组,用20个用户输入,然后将数组传递到<代码> GATSUM(I[])你可以创建测试数据,而不必输入……所有…二十……数字……每个…单…时间……用20个用户输入测试程序是一个噩梦。考虑用二十个元素填充一个int数组,用20个用户输入,然后将数组传递到<代码> GATSUM(I[])
函数。然后您可以创建测试数据,而无需输入…全部…二十个…数字…每个…单个…时间…呃。示例通常有用。示例通常有用。示例通常有用。示例通常有用。示例通常有用。