分享下自己写的计算余额宝上复利的代码,网上的复利计算器无法满足需求

分享下自己写的计算余额宝上复利的代码,网上的复利计算器无法满足需求

每年存10万10%的回报连续存20年后复利=6400249.9 (钱足够多的话10%的回报还是可以找到的)
每月存1万,10%的年回报率,连续存20年后复利=7666969
还是不如买房划算啊,二十年后七百多万估计还是买不起房
不过如果你坚持到30年的话就有22803253,两千多万了,复利还是要靠长时间积累才行
//复利计算 每年存100000,投资年收益10%的理财产品,连续存20年
    public static void fulicount20(){
        double total = 0;
        int monthadd = 100000;
        int times = 20;
        double monthup = 1.1;//1.005;
        total = monthadd;
        //x年后
        for(int i=0; i < times; i++ ){
            total = total*monthup;
            total += monthadd;
        }
        System.out.println("20年后复利=" + total);
        //每年存10万10%的回报连续存20年后复利=6400249.9
    }
    
    //复利计算 每月存10000,投资年收益10%的理财产品,连续存20年
    public static void fulicount20_month(){
        double total = 0;
        int monthadd = 10000;
        int times = 20*12;
        double monthup = 1+0.1/12;//1.005;
        total = monthadd;
        //x年后
        for(int i=0; i < times; i++ ){
            total = total*monthup;
            total += monthadd;
        }
        System.out.println("20年后复利=" + total);
        //每月存1万,10%的年回报率,连续存20年后复利=7666969
        //还是不如买房划算,二十年后七百多万估计还是买不起房
        //不过如果你坚持到30年的话就有22803253,两千多万了,复利还是要靠长时间积累才行
    }

 

 
自己写了个程序算了下,每个月存到余额宝上500块,按照现在的一万块每天1.3元的收益率,10年后有77448.9,30年后有396506

有三种需求:

第一种是每月存一定数额,连续存10年,然后再继续放10年,20年。

第二种是每月都存一定数额连续20年,30年。

第三种是前10年每月存一定数额,后10年存另外一个数额,再后10年每月取一定数额用(类似养老金领取),看最后剩下多少。

给出第二种需求的代码,其他两种需求稍微改改代码就可以了

 1 public class TestFuli {
 2 
 3     public static void main(String[] args) {
 4         fulicount();
 5     }
 6     
 7     //复利计算
 8     public static void fulicount(){
 9         double total = 0;
10         int monthadd = 1000;
11         int times = 3600;
12         int timecount = 0;
13         double dayup = 1.00013;
14         total = monthadd;
15         //10年后
16         for(int i=0; i < times; i++ ){
17             total = total*dayup;
18             //每个月增加
19             if(i%30 == 0){
20                 total += monthadd;
21                 timecount++;
22                 System.out.println("monthadd=" + total + " timecount=" + timecount);
23             }
24         }
25         System.out.println("10年后复利=" + total);
26         
27         //20年后
28         for(int i=0; i < times; i++ ){
29             total = total*dayup;
30             //每个月增加
31             if(i%30 == 0){
32                 total += monthadd;
33             }
34         }
35         System.out.println("20年后复利=" + total);
36         
37         //30年后
38         for(int i=0; i < times; i++ ){
39             total = total*dayup;
40             //每个月增加
41             if(i%30 == 0){
42                 total += monthadd;
43             }
44         }
45         System.out.println("30年后复利=" + total);
46     }
47 
48 }


monthadd=77157.51361112182 timecount=120
10年后复利=77448.92746593131
20年后复利=200317.0376022161
30年后复利=396506.5490823614

每个月存到余额宝上500块,按照现在的一万块每天1.3元的收益率,10年后有77448.9,30年后有396506
------------------------------------
每个月存1000块的话,30年后差不多有80万
10年后复利=154897.85493186262
20年后复利=400634.0752044322
30年后复利=793013.0981647228
--------------------------------------
每个月存一万的话就比较快了
10年后复利=1548978.549318626
20年后复利=4006340.7520443182
30年后复利=7930130.981647215
每个月存1万,30年后差不多800万
投资其他更高收益率的复利后就更多了,所以提前做好理财计划还是很重要的
 
---------------------------------------
每年存10万10%的回报连续存20年后复利=6400249.9 (钱足够多的话10%的回报还是可以找到的)
每月存1万,10%的年回报率,连续存20年后复利=7666969
还是不如买房划算啊,二十年后七百多万估计还是买不起房
不过如果你坚持到30年的话就有22803253,两千多万了,复利还是要靠长时间积累才行
 
posted @ 2013-11-04 18:23  大自然的流风  阅读(2241)  评论(0编辑  收藏  举报