*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