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

第二章第二十一题(金融应用:计算未来投资回报)(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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值