Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at newpackage.NewClass5.main(NewClass5.java:33)
at if(average[k]>second) and i dont know why its giving me that
我的代碼給我的錯誤我想找到並刪除每行的最小值和最大值,然後計算每個人的平均水平,使找到的贏家我的程序給我的錯誤ArrayIndexOutOfBoundsException異常
肖恩 8.4 5.6 7.2 9.2 8.1 5.7
喬治 5.4 8.7 9.9 6 7.6 8.3
金 7.5 5.2 5.9 9.1 8.5 9
Scanner input=new Scanner(System.in);
System.out.println("Enter the number of Swimmers");
int n = input.nextInt();
String[] name = new String[n];
System.out.println("Enter the number of Juries");
int m = input.nextInt();
double[] jurie=new double[m];
double[] average=new double[n];
for(int i=0;i<n;i++){
name[i] = input.next();
for(int pidh=0;pidh<m;pidh++){
jurie[i]=input.nextDouble();
double total = 0.0;
double max1 = jurie[pidh];
double min = jurie[pidh];
for(int q=0;q<m;q++){
if(jurie[pidh] > max1){
max1 = jurie[pidh];}
if(jurie[pidh] < min){
min = jurie[pidh];}
total=total + jurie[i];
}
average[i]=(total-(min+max1))/(m-2);
}
int pos=0;
double second = average[0];
for(int k=0;k<m;k++){
if(average[k]>second)
{
second = average[k];
pos = k;
}
}
System.out.println("\n" +name[pos] + " is the winner with " + second + " points.");
}
}
}
現在,它的工作!謝謝,如果有人仍然看這個線程。 值就打印超過10個,但我想以平均正確的數字,它給了我8.55,12.45,13.5 – Karoqi
@Karoqi不客氣:) – AntonH