public class J5_22 {
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Loan Amount:");
double loanAmount = input.nextDouble();
System.out.print("Number of year: ");
double numberOfYear = input.nextDouble();
System.out.print("Annual Interest Rate: ");
double annualInterestRate = input.nextDouble();//年利率
double balance = loanAmount;
double monthlyInterestRate = annualInterestRate /1200;//月利率
double monthlyPayment = (loanAmount * monthlyInterestRate)/
(1-(Math.pow(1 / (1 + monthlyInterestRate), numberOfYear*12)));//月账单
double totalPayment = monthlyPayment*numberOfYear*12;//总账单
System.out.printf("Monthly Payment %5.2f\n",monthlyPayment);
System.out.printf("Total Payment %6.2f\n",totalPayment);
System.out.print("Payment#\tInterest\tPrincipal\tBalance\n");
for(int i=1 ;i<=numberOfYear*12;i++) {
double interest = monthlyInterestRate * balance;
double printipal = monthlyPayment - interest;
balance = balance -printipal;
//System.out.println(i+ "\t"+interest+"\t"+printipal+"\t"+balance);
System.out.printf("%d \t\t%4.2f \t\t%5.2f \t %5.2f\n ",i,interest,printipal,balance);
}
}
}
java语言程序设计 第十版(基础篇)5.22
猜你喜欢
转载自blog.csdn.net/qq_41729287/article/details/83042973
今日推荐
周排行