第二章第二十一题(金融应用:计算未来投资回报)(Financial application: calculate future investment value)

    科技2022-07-10  111

    第二章第二十一题(金融应用:计算未来投资回报)(Financial application: calculate future investment value)

    *2.21(金融应用:计算未来投资回报)编写程序,读取投资总额、年利率和年数,然后使用下面的公式显示未来投资回报金额: 未来投资回报金额 = 投资总额 \times(1+月利率)^ (年数 \times 12)

    例如:如果输入的投资金额为1000,年利率为3.25%,年数为1,那么未来投资回报金额为1032.98。

    下面是一个运行示例:

    Enter investment amount :1000.56 Enter annual interest rate in percentage : 4.25 Enter number of year : 1

    *2.21(Financial application: calculate future investment value) Write a program that reads in investment amount, annual interest rate, and number of years and displays the future investment value using the following formula:

    For example, if you enter amount 1000, annual interest rate 3.25%, and number of years 1, the future investment value is 1032.98. Here is a sample run:

    Enter investment amount :1000.56 Enter annual interest rate in percentage : 4.25 Enter number of year : 1

    参考代码:

    package chapter02; import java.util.Scanner; public class Code_21 { public static void main(String[] args) { double FutureInvestmentValue, InvestmentAmount, AnnualInterestRate,InvestmentYear; Scanner Input; System.out.print("Enter investment amount : "); Input = new Scanner(System.in); InvestmentAmount = Input.nextDouble(); System.out.print("Enter annual interest rate in percentage : "); Input = new Scanner(System.in); AnnualInterestRate = Input.nextDouble(); System.out.print("Enter number of year : "); Input = new Scanner(System.in); InvestmentYear = Input.nextDouble(); FutureInvestmentValue = InvestmentAmount * Math.pow((1 + AnnualInterestRate/1200), (InvestmentYear * 12)); System.out.println("Future value is $" + FutureInvestmentValue); Input.close(); } } 结果显示: Enter investment amount : 1000.56 Enter annual interest rate in percentage : 4.25 Enter number of year : 1 Future value is $1043.9219854307503 Process finished with exit code 0
    Processed: 0.014, SQL: 8