第2章:财务应用程序:复利值

来源:互联网 发布:淘宝开店多久才有生意 编辑:程序博客网 时间:2024/04/30 11:27

/** * 财务应用程序:复利值。 * 假设每个月向银行帐号存100美元,年利率为5%,那么每月利率就是5%/12=0.00417。 * 第一个月之后,账户上的值就变成:100 * (1 + 0.00417) = 100.47。 * 第二个月:(100 + 100.47) * (1 + 0.00417) = 201.252。 * 编写程序显示六个月后账户的钱数。 */package Test;public class T215 {public static void main(String[] args) {final double save = 100;double sum = 0;double yearRates = 0.05;double monthRates = 0.00417;for (int i = 1; i < 7; i++){sum = (sum + save) * Math.pow(1 + monthRates, 1);System.out.println("The " + i + " months is " + sum + " douls!");}System.out.println(sum);}}