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
My code gives me that error i want to find and remove the minimum and maximum of each line then calculate the average of each one and make the find the the winner
Shaun 8.4 5.6 7.2 9.2 8.1 5.7
George 5.4 8.7 6 9.9 7.6 8.3
Kim 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.");
}
}
}