Я пытаюсь ранжировать свой массив в своем задании, но я не понимаю, как это сделать. Кто-нибудь может мне помочь? Заранее спасибо
Я добавил изображение полной инструкции по назначению.
Вот изображение моего назначения:
А вот и мой код:
public class Assignment_3_Question_1 {
// Here, I predefined my data set.
static int referenceScore[][]={{39,40,17,35,42,6},{40,41,27,41,42,36},{42,40,26,42,42,35}};
static int finalScore[][]={{39,40,17,35,42,6},{40,41,27,41,42,36},{42,40,26,42,42,35}};
static int scoreAmongOthers[][]=new int[3][6];
static int max;
static int rank = 1;
static int count = 0;
static int total = 0;
public static void main(String[] args) {
for (int k = 0; k < 10; k++){
max = referenceScore[0][0];
for (int team = 0; team < 3; team++){
for (int position = 0; position < 6; position++){
if (max < referenceScore[team][position]){
max = referenceScore[team][position];
}
}
}
for (int x = 0; x < 3; x++){
for(int y = 0; y < 6; y++){
if(referenceScore[x][y]==max){
scoreAmongOthers[x][y]=rank;
referenceScore[x][y]=0;
count++;
}
}
}
rank = count + 1;
}
// Print out the
System.out.println("\tP1\tP2\tP3\tP4\tP5\tP6\tTotal\tRank");
// Prints out the results and the rank for each team
for(int teamNb = 0; teamNb<3; teamNb++){
System.out.print("Team"+(teamNb+1));
for(int p=0; p<6; p++){
total = total + finalScore[teamNb][p];
System.out.print("\t" + finalScore[teamNb][p]+"("+ scoreAmongOthers[teamNb][p]+") ");
}
System.out.print("\t"+ total);
total = 0;
System.out.println();
}
}
}