所以我试图制定一个程序,它平均你的高尔夫比分。我编辑的标准平均计算器,使其工作:高尔夫比分计划?
import java.util.Scanner;
public class Test {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int total = 0;
int score;
int average;
int counter = 0;
while (counter >= 0){
score = input.nextInt();
total = total + score;
counter++;
}
average= total/10;
System.out.println("Your average score is "+ average);
}
}
但是,当我输入分数,我可以继续进入无限的成绩,它从不平均值他们。它只是继续期待另一个分数。我知道它与这条线有关:
while (counter >= 0){
但我不知道该怎么办,所以它的工作原理是正确的。
当'counter'不低于或相等更大,你'while'循环才会停止为零,并且您用'counter ++'递增'counter',所以绝不是这种情况。你确定这就是你想要它工作的方式?或者你还希望你的循环结束? – birryree