今天通过一个案例来将实现一个排序的功能。
public static void main(String[] args) {
double sum_ZS = 0;// 定义变量
double sum_LS = 0;
double sum_WW = 0;
double avg_ZS = 0;
double avg_LS = 0;
double avg_WW = 0;
double[] scores_ZS = { 9.65, 9.40, 9.95, 9.55, 9.65, 9.80, 9.75, 9.20 };
double[] scores_LS = { 9.15, 9.80, 9.45, 9.65, 9.90, 9.85, 9.70, 9.30 };
double[] scores_WW = { 9.40, 9.45, 9.50, 9.30, 9.95, 9.20, 9.60, 9.85 };
Arrays.sort(scores_ZS);// 排序
Arrays.sort(scores_LS);
Arrays.sort(scores_WW);
scores_ZS[0] = scores_ZS[7] = 0;// 最高和最低分置零
scores_LS[0] = scores_LS[7] = 0;
scores_WW[0] = scores_WW[7] = 0;
// 遍历求和
for (int i = 0; i < scores_WW.length; i++) {
sum_WW += scores_WW[i];
}
for (int i = 0; i < scores_WW.length; i++) {
sum_LS += scores_LS[i];
}
for (int i = 0; i < scores_WW.length; i++) {
sum_ZS += scores_ZS[i];
}
// 求平均分
avg_ZS = sum_ZS / 6;
avg_LS = sum_LS / 6;
avg_WW = sum_WW / 6;
System.out.println("张三选手的最终平均得分:" + avg_ZS);
System.out.println("李四选手的最终平均得分:" + avg_LS);
System.out.println("王五选手的最终平均得分:" + avg_WW);
}
以上i就是代码