这题太恶心了,直接放代码,变量rate写的有点懵逼,估计也就我自己看得懂
import java.util.Scanner;
public class LoanTest{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double capital = sc.nextDouble();
int year = sc.nextInt();
System.out.println("贷款额:"+String.format("%.0f",capital));
System.out.println("贷款年限:"+year);
System.out.println("利率 月还款额 总还款额");
// double rate = 0.05; //利率
double sum = 0; //总还款额
double month = 0; //月还款额
for (double rate = 0.05; rate <= 0.08125; ){
month = (capital * (rate / 12) * Math.pow(1 + rate / 12,year * 12)) /
(Math.pow(1 + rate / 12, year * 12) - 1);
sum = month * 12 * year;
rate = rate * 100;
System.out.println(String.format("%.3f",rate) + "% "+String.format("%.2f",month) +" "+String.format("%.2f",sum));
rate = rate / 100;
rate = rate + 0.00125;
}
}
}