Ranking array Java

问题描述 投票:0回答:1

我正在尝试在我的作业中对数组进行排名,但是我不知道该怎么做。有人能帮我吗?预先谢谢你

我添加了完整作业说明的图像。

这是我的任务的图像:

enter image description here

这是我的代码:

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();
        }
    }
}
java arrays rank
1个回答
0
投票

因此,我知道练习的重点是练习使用数组。您已经在comment中概述了所需的算法。这是我的实现。

© www.soinside.com 2019 - 2024. All rights reserved.