统计信息

  • 访问数:10944
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P6Q22

2008-04-17 22:54:55

天气: 晴朗 心情: 高兴

/*filename:P6Q22.java
 *Name:Wang Chaoran
 *Description:
(Computing the weekly hours for each employee) Suppose the weekly hours for all employees are
stored in a two-dimensional array. Each row records an employee's seven-day work hours with
seven columns. For example, the following array stores the work hours for eight employees.
Write a program that displays employees and their total hours in decreasing order of the total hours.
*/
class P6Q22{
  public static void main(String[] args){
    int[][] test={{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 sum = 0;
    int[] hour=new int[test.length];
    int[] trace=new int[test.length];
    for(int i=0;i<test.length;i++){
      for(int j=0;j<test[i].length;j++)
        hour[i]+=test[i][j];
      trace[i]=i;
  }
    sort(hour,trace);
    print(hour,trace);
}
  static void sort(int[] hour,int[] trace){
    for(int i=0;i<hour.length;i++){
    int current = hour[i];
    int current1= trace[i];
    int j;
    for(j=i-1;j>=0&&hour[j]<current;j--){
      trace[j+1]=trace[j];
      hour[j+1]=hour[j];
    }
    trace[j+1]=current1;
    hour[j+1]=current;
    }
  }
  static void print(int[] hour,int[] trace){
    for(int i=0;i<hour.length;i++){
    System.out.println("Employee"+trace[i]+"  "+hour[i]+" hours");
    }
  }
}

加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd