我们应该创建一个循环,重复学生所需的次数。在设置一个不在代码中的预定计数上运行的循环时,我完全迷失了。
我们必须创建循环。我甚至都不知道从哪里开始,因为书中没有任何内容可以让我看到这种情况。
感谢任何帮助,让我朝着正确的方向前进。
import java.util.*;
public class TestScoreStatistics
{
public static void main (String args[])
{
int score;
int total = 0;
int count = 0;
int highest;
int lowest;
final int QUIT = 999;
final int MIN = 0;
final int MAX = 100;
Scanner input = new Scanner(System.in);
System.out.print("How many scores would you like to enter >> ");
enterCount = input.nextInt();
System.out.print("Enter a score >> ");
score = input.nextInt();
//Create a while statement that will loop for the amount entered
while( count != QUIT )
{
}
System.out.print("Enter another score >> ");
score = input.nextInt();
}
System.out.println(count + " scores were entered");
System.out.println("Highest was " + highest);
System.out.println("Lowest was " + lowest);
System.out.println("Average was " + (total * 1.0 / count));
}
}
答案 0 :(得分:0)
因此。您似乎要求输入分数,直到用户输入了与enterCount:
中定义的分数一样多的分数List<Integer> scores = new ArrayList<Integer>();
while( count < enterCount ) {
System.out.print("Enter another score >> ");
score = input.nextInt();
scores.add(score);
count++;
}
您可能需要定义某种类型的List,其中包含分数。