liang183 发表于 2016-12-24 16:17:32

java编程财务应用程序:显示分期还贷时间表

package nameyu;import java.util.Scanner;public class Test {    public static void main(String[] args) {      // TODO Auto-generated method stub      Scanner input=new Scanner(System.in);      System.out.print("Loan Amount:");      double loan=input.nextDouble();      System.out.print("Numeber of years:");      int years =input.nextInt();      System.out.print("Annual Interest Rate:");      double InterestRate=input.nextDouble();      double MonthlyPayment=loan*(InterestRate/1200)/(1-1/Math.pow(1+InterestRate/1200, years*12));      double TotalPayment=MonthlyPayment*years*12;      System.out.printf("%-4.2f%s%-4.2f%n",MonthlyPayment,"",TotalPayment);      System.out.println();      System.out.println("Payment#"+"\t"+"Interest"+"\t\t\t"+"Principal"+"\t\t\t"+"Balance");      double balance=loan;      for(int i=1;i<=years*12;i++){            doubleInterest=(InterestRate/1200)*balance;            double principal=MonthlyPayment-Interest;            balance=balance-principal;            System.out.println(i+"\t\t"+Interest+"\t\t"+principal+"\t\t"+balance);      }    }}
页: [1]
查看完整版本: java编程财务应用程序:显示分期还贷时间表