2012年5月30日 星期三

Java Basic(23)-Compound Interest Program


金額=本金(1+利率)^
^ =power to



class apples{
public static void main(String args[]){
double amount;
double principal = 10000;
double rate = .01;
for (int day=1;day<=20;day++){
amount=principal*Math.pow(1+rate, day); 這是公式
System.out.println(day + " "+amount);
}
}
}

Program將運行這樣的:
1 10100.0
2 10201.0
3 10303.010000000002
4 10406.0401
5 10510.100501
6 10615.201506010002
7 10721.353521070101
8 10828.567056280803
9 10936.852726843608
10 11046.221254112046 一天你能得到多少利息!
11 11156.683466653169
12 11268.250301319698
13 11380.932804332895
14 11494.742132376223
15 11609.689553699987
16 11725.786449236986
17 11843.044313729357
18 11961.47475686665
19 12081.089504435316
20 12201.900399479671

沒有留言:

張貼留言