编写程序,计算贷款的每月支付额。程序要求用户输人货款的年利率、总金额和年数,程序计算月支付金领和总偿还金额,并将结果显示输出。计算货款的月支付额公式为
贷款总额×月利率/1-(1/(1十月利率)^年数x12)
提示:可使用 Math. sqrt (double d)方法汁算数的平方根,使用 Math. pow (double a,double b)方法计算a^b。
import java.util.Scanner;
public class program2 {
public static void main(String[ ] args){
Scanner input = new Scanner(System.in);
System.out.printf("请输入年利率:");
double annualyRate = input.nextDouble();
double monthlyRate = annualyRate / 12;
System.out.printf("请输入贷款总额:");
double loanAmout = input.nextDouble();
System.out.printf("请输入贷款年数:");
double numYear = input.nextDouble();
double monpay =monthlyRate * loanAmout / (1-1/Math.pow(1+monthlyRate,numYear*12));
double toatlpay = monpay * 12 * numYear;
System.out.printf("月支付金额:"+monpay);
System.out.printf("总支付金额:"+numYear);
}
}