第二章第二十题(金融应用:计算利息)(Financial application: calculate interest)

第二章第二十题(金融应用:计算利息)(Financial application: calculate interest)

  • *2.20(金融应用:计算利息)如果知道余额和年利率百分比,就可以使用下面的公式计算下个月的利息:
    利息 = 余额 * (年利率百分比 / 1200)

    编写程序,读取余额和年利率百分比,打印下个月的利息。下面是一个运行示例:
    Enter balance and interest rate (e.g.,3 for 3%):1000 3.5

    The interest is 2.91667

    *2.20(Financial application: calculate interest) If you know the balance and the annual percentage interest rate, you can compute the interest on the next monthly payment using the following formula:
    interest = balance * (annualInterestRate/1200)

    Write a program that reads the balance and the annual percentage interest rate and displays the interest for the next month. Here is a sample run:
    Enter balance and interest rate (e.g.,3 for 3%):1000 3.5

    The interest is 2.91667

  • 参考代码:

package chapter02;

import java.util.Scanner;

public class Code_20 {
    public static void main(String[] args) {
        double Interest,Balance,AnnualInterestRate;

        System.out.print("Enter balance and interest rate "
                + "(e.g., 3 for 3%) : ");
        Scanner BalanRateInput = new Scanner(System.in);
        Balance = BalanRateInput.nextDouble();
        AnnualInterestRate = BalanRateInput.nextDouble();

        Interest = Balance * (AnnualInterestRate / 1200);
        System.out.println("The interest is " + Interest);

        BalanRateInput.close();
    }
}

  • 结果显示:
Enter balance and interest rate (e.g., 3 for 3%) : 1000 3.5
The interest is 2.916666666666667

Process finished with exit code 0

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值