码迷,mamicode.com
首页 > 其他好文 > 详细

HW4.21

时间:2016-08-16 10:31:22      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW4.21

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5775248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!