mortgage.java

来自「Java2核心技术卷一 配套源码,看了还不错」· Java 代码 · 共 31 行

JAVA
31
字号
/**
 * @version 1.10 10 Mar 1997 
 * @author Gary Cornell
 */

import corejava.*;
import java.text.*;

public class Mortgage
{  public static void main(String[] args)
   {  double principal;
      double yearlyInterest;
      int years;
 
      principal = Console.readDouble
         ("Loan amount (no commas):");
      yearlyInterest = Console.readDouble
         ("Interest rate in % (ex: use 7.5 for 7.5%):")/100; 
      years = Console.readInt("The number of years:");
         
      double monthlyInterest = yearlyInterest / 12;
      double payment = principal * monthlyInterest 
         / (1 - (Math.pow(1/(1 + monthlyInterest), 
            years * 12)));
      System.out.println("Your payment is ");
      NumberFormat nf = NumberFormat.getCurrencyInstance();
      System.out.println(nf.format(payment));
   }
}    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?