import java.util.*;
import java.util.Arrays;
public class EmployeeWeeklyHours{
public static void main(String[] args) {
int[][] employeeHours= new int[][] {
{ 2, 4, 3, 4, 5, 8, 8},
{ 7, 3, 4, 3, 3, 4, 4},
{ 3, 3, 4, 3, 3, 2, 2},
{ 9, 3, 4, 7, 3, 4, 1},
{ 3, 5, 4, 3, 6, 3, 8},
{ 3, 4, 4, 6, 3, 4, 4},
{ 3, 7, 4, 8, 3, 8, 4},
{ 6, 3, 5, 9, 2, 7, 9}};
int [] finalHours = new int[8];
for (int i = 0; i < finalHours.length; i++) {
int total = 0;
for (int j = 0; j < finalHours.length - 1; j++) {
total += employeeHours[i][j];
finalHours[i] = total;
}
}
java.util.Arrays.sort(finalHours);
int[] sort = new int[finalHours.length];
for (int i = 0; i < finalHours.length; i++)
sort[i] = finalHours[i];
for (int i = 7; i > -1; i--)
System.out.println(sort[i]);
}
}
员工 0:2 4 3 4 5 8 8
员工 1:7 3 4 3 3 4 4
员工 2:3 3 4 3 3 2 2
员工 3:9 3 4 7 3 4 1
员工 4:3 5 4 3 6 3 8
员工 5:3 4 4 6 3 4 4
员工 6:3 7 4 8 3 8 4
员工 7:6 3 5 9 2 7 9
从我的代码中可以看出,我应该按降序列出每个员工的总工作时间。但是,我似乎很难在总工时旁边显示员工编号。
EG “员工 7 工作了 42 小时。
有什么方法可以在排序后的数字旁边列出员工编号,而无需对其进行硬编码?我觉得我的问题有一个简单的答案,但现在什么都没有想到。