HW7.4

时间:2022-12-06 06:18:52

HW7.4

 public class Solution
 {
     public static void main(String[] args)
     {
         int[] employee = new int[8];
         int[] totalTime = new int[8];
         int temp;

         int[][] detailTime =
         {
             {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}
         };

         for(int i = 0; i < 8; i++)
         {
             for(int j = 0; j < 7; j++)
                 totalTime[i] += detailTime[i][j];
             employee[i] = i;
         }

         for(int i = 0; i < 8; i++)
         {
             for(int j = i; j < 8; j++)
             {
                 if(totalTime[j] > totalTime[i])
                 {
                     temp = totalTime[j];
                     totalTime[j] = totalTime[i];
                     totalTime[i] = temp;
                     temp = employee[i];
                     employee[i] = employee[j];
                     employee[j] = temp;
                 }
             }
         }

         for(int i = 0; i < 8; i++)
             System.out.println("Employee " + employee[i] + " work " + totalTime[i] + " hours");
     }
 }

相关文章