金融应用,计算未来投资回报值 Exercise06_07
1 import java.util.Scanner; 2 /** 3 * @author 冰樱梦 4 * 时间:2018年下半年 5 * 题目:金融应用,计算未来投资回报值 6 * 7 */ 8 public class Exercise06_07 { 9 public static void main(String[] args){ 10 Scanner input=new Scanner(System.in); 11 System.out.println("The amount invested: "); 12 double investmentAmount=input.nextDouble(); 13 System.out.println("Annual interest rate: "); 14 double monthlyInterestRate=input.nextDouble()/12/100; 15 System.out.printf("%-10s %10s\n","Years","Future Value"); 16 for(int i=1;i<=30;i++){ 17 System.out.printf("%-10s %10s\n",i,futureInvestmentValue(investmentAmount,monthlyInterestRate,i)); 18 } 19 20 } 21 public static double futureInvestmentValue(double investmentAmount,double monthlyInterestRate,int years){ 22 return (int)(investmentAmount*(Math.pow((1+monthlyInterestRate),12*years))*100)/100.0; 23 24 } 25 }