Java语言程序设计(基础篇)第十版 5.21


public class J5_21 {

	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: ");
		int loanAmount = input.nextInt();
		System.out.print("Number of Years: ");
		int year = input.nextInt();
		
		
		double monthlyPayment , totalPayment,monthlyRate;
		System.out.println("Interest Rate ");
		System.out.print("\tMonthly Payment");
	    System.out.println("\t\tTotal Payment");
	    
		for(double rate = 5.0;rate<=8.0;rate += 0.125) {
			
			monthlyRate= rate/1200;
			
			 monthlyPayment = loanAmount * monthlyRate / 
		 (1 - (Math.pow(1 / (1 + monthlyRate), year * 12)));
			
			 totalPayment = monthlyPayment * year * 12;
			
			
			 System.out.printf("%5.3f%c %20.2f %20.2f\n", rate, 
		                '%', monthlyPayment, totalPayment);
		}
		
		
	}

}

猜你喜欢

转载自blog.csdn.net/qq_41729287/article/details/83038301