2 回答
TA贡献1891条经验 获得超3个赞
您必须在 for 循环之外创建一个变量,并将每次迭代的月薪相加,例如
int annualSalary = 0;
for(int month = 1; month <= 12; month++){
System.out.print("How many extra hours did you work this month?");
double extraHoursPerMonth = scan.nextInt();
double bonusSalary = extraHoursPerMonth*bonusSalaryPerHour;
double totalMonthlySalary = basicSalary + bonusSalary;
System.out.println("Your salary for this month is $" +
totalMonthlySalary);
}
System.out.println("Your annul salary for this year is $" + annualSalary);
TA贡献1811条经验 获得超6个赞
如果你想要年薪,你可以通过将月薪乘以 12 来获得。
double anualSalary = basicSalary*12;
如果你想要整体工资,你应该在anualSalary声明之后和 for 循环之前声明一个变量。
double overalSalary = anualSalary;
然后在 for 循环的每个循环中添加奖金工资。
...
overalSalary += bonusSalay;
...
添加回答
举报