当我尝试这样做时,我在编译某些数组时遇到了一些问题并且编译器会收到错误。我也试过像Arrays.sort那样做,但没有运气。
import java.util.Scanner;
public class CH6PA
{
private static double difficulty;
private static int score;
private double[] average = new double[7];
public static void main(String[]args)
{
Scanner keyboard = new Scanner (System.in);
do
{
System.out.println("Enter the level of difficulty (1.2-3.8)");
difficulty = keyboard.nextDouble();
}
while (difficulty<1.2 || difficulty>3.8);
int[] judge = new int[7];
for(int i = 0; i<judge.length; i++)
{
System.out.println("Enter the difficulty score for each judge (0-10)");
System.out.println("Enter the score for judge" + (i+1));
judge[i]=keyboard.nextInt();
while(score > 0 && score <=10);
}
sort(judge, judge.length);
System.out.println("Average = " + (judge[3] + judge[4] + judge[5]));
}
}
答案 0 :(得分:0)
while(得分&gt; 0&amp;&amp;得分&lt; = 10);似乎是错的。得分的价值是什么?
为什么两个嵌套循环,其中while()循环不会执行任何操作;。
答案 1 :(得分:0)
分数没有分配给它,因此你要比较空值。
答案 2 :(得分:0)
我相信你的意思是:
do {
System.out.println("Enter the score for judge" + (i+1));
judge[i]=keyboard.nextInt();
} while(judge[i] > 0 && judge[i] <=10); }
目前,judge[i]
将从int
读取stdin
(如果已编译)
该行:
while(score > 0 && score <=10);
现在没有任何意义,因此您会收到编译错误。