Java 如何使用循环查找数组中的最低分数和所有分数>;或者=100?
这是我所拥有的,应用程序是确定一系列分数的平均值、最低值和完美值。我算出了平均分,但我试图算出满分,但我没有得到任何输出?我看不出我哪里出错了?我也不确定如何在所有分数中找到最低的。谁能解释我做错了什么?和/或如何使用循环查找最低分数Java 如何使用循环查找数组中的最低分数和所有分数>;或者=100?,java,arrays,loops,Java,Arrays,Loops,这是我所拥有的,应用程序是确定一系列分数的平均值、最低值和完美值。我算出了平均分,但我试图算出满分,但我没有得到任何输出?我看不出我哪里出错了?我也不确定如何在所有分数中找到最低的。谁能解释我做错了什么?和/或如何使用循环查找最低分数 int[] scores = new int[10]; int score = 0; int count = 0; int total = 0; final int QUIT = 909; final int
int[] scores = new int[10];
int score = 0;
int count = 0;
int total = 0;
final int QUIT = 909;
final int MAX = 10;
Scanner input = new Scanner(System.in);
System.out.print("Please enter your scores: ");
score = input.nextInt();
while(count < MAX && score != QUIT)
{
if(score != QUIT)
{
scores[count] = score;
total += scores[count];
System.out.print("Enter next quiz score or enter " + QUIT + " to finish: ");
score = input.nextInt(); } count++;
}
System.out.println("The scores entered were: ");
for(int x = 0; x < count; ++x)
System.out.print(scores[x] + " \n");
System.out.println("The average of all scores: " + (total * 1.0 / count));
System.out.println("Your lowest score: "); //not sure how to loop through to find the lowest score
System.out.println("All perfect scores: ");
for(int x = 0; x >= scores.length; ++x)
{
if(scores[x] >= 100)
{
System.out.print(scores[x]); //not getting any output and I dont know why
int[]分数=新的int[10];
智力得分=0;
整数计数=0;
int-total=0;
最终int QUIT=909;
最终int最大值=10;
扫描仪输入=新扫描仪(System.in);
System.out.print(“请输入您的分数:”);
score=input.nextInt();
while(count=scores.length;++x)
{
如果(分数[x]>=100)
{
System.out.print(分数[x]);//没有得到任何输出,我不知道为什么
有一个名为最小值的新字段
,并将其设置为整数。最大值
在while循环的每个迭代中计算
minimum = Math.min (minimum, score);
也
永远不会成功,所以试试吧
for(int x = 0; x < scores.length; ++x)
for(int x=0;x
试着用x
最小值应设置为最大负值。只有在数据类型为无符号时才使用零。混乱获胜:)如果要查找较小的值,请使用大于任何实际值(或第一个实际值)的值初始化所以它肯定会被覆盖。=>Integer.MAX\u VALUE
。它将永远保持在MIN\u VALUE
,因为没有什么比这更重要了。@zapl今天早上没有足够的咖啡。你说得很对。除非OP在她的代码中检查这个值,否则一切都毫无意义。
for(int x = 0; x >= scores.length; ++x)
for(int x = 0; x < scores.length; ++x)
for(int x = 0; x >= scores.length; ++x)