java复利计算,该好好做定期理财了,不然以后植发都植不起,只能戴帽子

 public static void main(String[] args) {
        int principal = 40000;//本金
        float interest_rate = 0.043f;//利率
        int every_money = 4000;//每次投增加金额
        double count_time = 9;//投入次数,相当于三年,农行理财产品,4个月投一次,一年投三次,这里我投3年
        double total_sum;//本金+利息 总金额

        /**
         * 规则是,每次投都必须增加五千的金额
         */
        total_sum = countMoney(principal, interest_rate, every_money, count_time);
        System.out.println("本息的总金额: " + total_sum);
        System.out.println("复利赚取的利息: " + (total_sum-principal-every_money*count_time));
    }

    private static double countMoney(int principal, float interest_rate, int every_money, double count_month) {
        double total_sum = 0;
        for (int i = 1; i <= count_month; i++) {
            if(total_sum == 0){
                total_sum = (principal) * (1+interest_rate);
            }else{
                total_sum = (principal+every_money) * (1+interest_rate);
            }
            principal = (int) total_sum;
            System.out.println("第"+i+"次投的本息:"+total_sum);
        }
        return total_sum;
    }

java复利计算,该好好做定期理财了,不然以后植发都植不起,只能戴帽子_第1张图片

你可能感兴趣的:(复利理财,Java)