输出员工姓名,工资
(员工姓名怎么输出)
}
System.out.println("工资总额:"+totalSalary);
}
}
java输出员工姓名,工资
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注public static void main(String[] args) { YuanGong[] st = { new YuanGong("张三",25,1000,3), new YuanGong("李四",28,2500,2), new YuanGong("小明",22,1000,3), new YuanGong("小红",23,2500,2), new YuanGong("赵四",35,3500,1) }; for (int i = 0;i<st.length;i++){ int sum = 0; // System.out.printf("姓名:"+st[i].name+" 年龄:"+st[i].age+" 工资:"+st[i].gongzi+" 工作内容:"); System.out.printf("姓名:%s 年龄:%d 工资:%.2f 工作内容:",st[i].name,st[i].age,st[i].gongzi); st[i].work(st[i].job); } int sum = 0; for (int a=0;a<st.length;a++){ //平均工资 sum+=st[a].gongzi; } System.out.println("工资总额为:"+sum); System.out.println("平均工资为:"+sum/st.length); } } class YuanGong { String name; int age; double gongzi; int job; public YuanGong() { } public YuanGong(String name, int age, double gongzi, int job) { this.name = name; this.age = age; this.gongzi = gongzi; this.job = job; } public void work(int job){ if (job==1){ System.out.println("在办公室喝茶"); }else if (job==2){ System.out.println("在外跑业务"); }else if (job==3){ System.out.println("在厂房工作"); }else { System.out.println("工种有误"); } }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报