我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 郁闷
/*P4Q5
* Name:Wang Chaoran
* Description:5 (Comparing loans with various interest rates)
Write a program that lets the user enter the loan amount and loan period in number
of years and displays the monthly and total payments for each interest rate starting
from 5% to 8%, with an increment of 1/8. Suppose you enter the loan amount 10,000 for
five years; display a table as follows:
Loan Amount: 10000
Number of Years: 5
Interest Rate Monthly Payment Total Payment
5% 188.71 11322.74
5.125% 189.28 11357.13
5.25% 189.85 11391.59
...
7.85% 202.16 12129.97
8.0% 202.76 12165.83
*/
import java.util.Scanner;
public class P4Q5
{
public static void main(String[]args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Please input the Loan Amount:");
double loanAmount=scan.nextDouble();
System.out.println("Please input the Number of Years:");
double numberOfyears=scan.nextDouble();
System.out.printf("%-18s%-18s%-18s","Interest Rate","Monthly Payment","Total Payment");
System.out.println("\n");
double interestRate=5,monthlyPayment=0,totalPayment;
for(int i=1;i<= numberOfyears*12;i++)
{
totalPayment=10000*Math.pow((1+(interestRate/100)),4);
System.out.printf("%-17f%1s%-18f%-18f",interestRate,"%",monthlyPayment,totalPayment);
}
}
}
导入论坛查看(60)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing