假設(shè)某員工今年的年薪是30000元,年薪的年增長率6%。編寫一個Java應(yīng)用程序計算該員工
假設(shè)某員工今年的年薪是30000元,年薪的年增長率6%。編寫一個Java應(yīng)用程序計算該員工10年后的年薪, 并統(tǒng)計未來10年(從今年算起)總收入。(知識點: 循環(huán)語句for)
public class SalaryCalculator {
? ? public static void main(String[] args) {
? ? ? ? int currentSalary = 30000;
? ? ? ? double growthRate = 0.06;
? ? ? ? int numberOfYears = 10;
? ? ? ? double totalIncome = 0;
? ? ? ? for (int i = 1; i <= numberOfYears; i++) {
? ? ? ? ? ? double yearSalary = currentSalary * Math.pow(1 + growthRate, i);
? ? ? ? ? ? totalIncome += yearSalary;
? ? ? ? ? ? System.out.println("第 " + i + " 年的年薪是 " + yearSalary + " 元");
? ? ? ? }
? ? ? ? System.out.println("未來10年總收入是 " + totalIncome + " 元");
? ? }
}
標(biāo)簽: