Java实现描述公司财务部门发工资的情况可能输出如下信息: XXX 员工工资大于等于10000 ,XXX 员工工资大于等于5000小于10000,XXX 员工工资大于等于2000小于5000,XXX 员工工资大于等于1000小于2000,XXX 员工工资小于1000则需要补助
时间: 2023-11-08 09:09:45 浏览: 124
ChitGPT: 你可以通过使用Java中的条件语句和循环来实现这个问题。首先需要定义一个员工类,用于存储员工的姓名和工资信息。然后,遍历员工列表,根据不同的工资范围进行分类统计,最后输出对应的信息即可。以下是代码示例:
```
class Employee {
String name;
double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
}
public class Payroll {
public static void main(String[] args) {
// 假设有5个员工
Employee[] employees = new Employee[]{
new Employee("Tom", 15000),
new Employee("Jack", 8000),
new Employee("Lily", 3000),
new Employee("Lucy", 1500),
new Employee("Andy", 500)
};
int count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0;
for (Employee employee : employees) {
if (employee.salary >= 10000) {
count1++;
} else if (employee.salary >= 5000) {
count2++;
} else if (employee.salary >= 2000) {
count3++;
} else if (employee.salary >= 1000) {
count4++;
} else {
count5++;
}
}
System.out.println(count1 + " 员工工资大于等于10000");
System.out.println(count2 + " 员工工资大于等于5000小于10000");
System.out.println(count3 + " 员工工资大于等于2000小于5000");
System.out.println(count4 + " 员工工资大于等于1000小于2000");
System.out.println(count5 + " 员工工资小于1000则需要补助");
}
}
```
阅读全文