public static void main(String[] args) {
double invest = 280000;
double yearRate = 0.0655;
double monthRate = yearRate/12;
int year = 15;
int month = year * 12;
double monthIncome = (invest* monthRate * Math.pow(1+monthRate,month))
/(Math.pow(1+monthRate,month)-1);
System.out.println("每月本息金额 : "+ monthIncome);
// 每月本金 = 本金×月利率×(1+月利率)^(还款月序号-1)÷((1+月利率)^还款月数-1)
double monthCapital = 0;
for(inti=1;i<month+1;i++){
monthCapital = (invest* monthRate * (Math.pow((1+monthRate),i-1)))
/(Math.pow(1+monthRate,month)-1);
System.out.println("第"+ i + "月本金: "+ monthCapital);
}
double monthInterest = 0;
double capital = invest;
double sumAvg = 0;
double tmpCapital = 0;
for(inti=1;i<month+1;i++){
capital = capital - tmpCapital;
monthInterest = capital * monthRate;
tmpCapital = (invest* monthRate * (Math.pow((1+monthRate),i-1)))
/(Math.pow(1+monthRate,month)-1);
System.out.println("第"+ i + "月利息: "+ monthInterest);
sumAvg += monthInterest
}
System.out.println
("总利息: "+ sumAvg);
DecimalFormat decimalFormat = new DecimalFormat("0.00");
System.out.println
("总利息输出两位小数: "+ Double.parseDouble(decimalFormat.format(sumAvg)));
}