题目:
月支付额度 =贷款额度 * 月利率/(1-1/(1+月利率)^(年数*12))
总支付额度 = 月支付额度年数12
代码实现:
public class InterestRate { //根基公式计算月供,总供
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入年利率:例如:6.08:");
double rate = input.nextDouble();
double monelyrate = rate/1200;//月利率
System.out.print("请输入你的贷款额度:");
double numer = input.nextDouble();
System.out.print("请输入你的贷款年限:");
int year = input.nextInt();
double monthlyPaymen = (numer*monelyrate)/(1-1/Math.pow((1+monelyrate),year*12));//
double totalPaymen = monthlyPaymen*year*12;
System.out.println("月支付是:¥"+(int)(monthlyPaymen*100)/100.0);
System.out.println("总支付是:¥"+(int)(totalPaymen*100)/100.0);
}
}