提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
与的复利计算。
/** from 时代Java公众号**/ public class Main { public static void main(String args[]) { double amount; // amount on deposit at end of each year double principal = 1000.0; // initial amount before interest double rate = 0.05; // interest rate // display headers System.out.printf("%s%20s%n", "Year", "Amount on deposit"); // calculate amount on deposit for each of ten years for (int year = 1; year <= 10; year++) { // calculate new amount for specified year amount = principal * Math.pow(1.0 + rate, year);