标签:
1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Loan Amount: "); 10 double loanAmount = input.nextDouble(); 11 System.out.print("Number of Years: "); 12 int numberOfYears = input.nextInt(); 13 14 input.close(); 15 16 System.out.printf("%s\t\t%s\t\t%s", "Interest Rate", "Monthly Payment", "Total Payment"); 17 System.out.println(); 18 19 double interestRate; 20 double monthlyPayment; 21 double totalPayment; 22 23 for(double i = 0.05; i <= 0.08; i += 0.00125) 24 { 25 interestRate = i; 26 monthlyPayment = loanAmount * (interestRate / 12) / 27 (1 - 1 / Math.pow(1 + interestRate / 12, numberOfYears * 12)); 28 totalPayment = monthlyPayment * numberOfYears * 12; 29 30 System.out.printf("%f\t\t%f\t\t%f", i, monthlyPayment, totalPayment); 31 System.out.println(); 32 } 33 } 34 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5775248.html