请教一个问题,关于java的小问题

小明往银行里存了 987654321 元钱 每年银行利息7.5% 并存入账户,小明每年最后一天会取出 87654321元钱,并且之后每年会少取1.32%。请问小明取钱,取到第几年的时候,发现钱不够取了。

package com.csdn;

import java.text.DecimalFormat;

public class Person {

    public static void main(String[] args) {
        double money = 987654321;
        double takeOut = 87654321;
        int year = 0;
        while (money > 0) {
            // 每年银行利息7.5% 并存入账户
            money = money * (1 + 0.075);
            // 每年最后一天会取出 87654321元钱
            money -= takeOut;
            ++year;
            System.out.println("第" + year + "年,当前账户余额为:" + formatFloatNumber(money));
            // 并且之后每年会少取1.32%
            takeOut -= takeOut * 0.0132;

        }

    }

    public static String formatFloatNumber(double value) {
        if (value != 0.00) {
            DecimalFormat df = new DecimalFormat("##.00");
            return df.format(value);
        } else {
            return "0.00";
        }

    }

}

img

可以取到60年,楼上兄弟把利率填错了

package test;

 

import java.text.DecimalFormat;

 

public class Test{

 

    public static void main(String[] args) {

        double money = 987654321;

        double takeOut = 87654321;

        int year = 0;

        while (money > 0) {

            // 每年银行利息7.5% 并存入账户

            money = money * (1 + 0.075);

            // 每年最后一天会取出 87654321元钱

            money -= takeOut;

            ++year;

            System.out.println("第" + year + "年,当前账户余额为:" + formatFloatNumber(money));

            // 并且之后每年会少取1.32%

            takeOut -= takeOut * 0.0132;

 

        }

 

    }

 

    public static String formatFloatNumber(double value) {

        if (value != 0.00) {

            DecimalFormat df = new DecimalFormat("##.00");

            return df.format(value);

        } else {

            return "0.00";

        }

 

    }

 

}