【发布时间】:2023-03-08 08:41:02
【问题描述】:
我正在尝试使用嵌套的 for 循环显示抵押贷款程序的表格。外循环由利率控制,因为它从起始利率处理到结束,而内循环由以年为单位的开始期限到以年为单位的结束期限控制。 每次迭代后利率增加0.25,年份增加5。
当生成多个列时,我在计算付款时遇到困难。
这是预期的输出:
Interest 15 Years 20 Years 25 Years
4.000 739.69 605.98 527.84
4.250 752.28 619.23 541.74
4.500 764.99 632.65 555.83
4.750 777.83 646.22 570.12
5.000 790.79 659.96 584.59
这是我的输出:
Interest
Rate 15 Years 20 Years 25 Years
4.000 739.69 739.69 739.69
4.250 752.28 752.28 752.28
4.500 764.99 764.99 764.99
4.750 777.83 777.83 777.83
5.000 790.79 790.79 790.79
这是我必须计算的贷款金额:
//startingYear is the first term entered by the user
//ending Year is the last term entered by the user
displayTableHeader(startingYear, endingYear, startCount, yearCounter);
//sCountaRate is the starting interest rate
// n determines how many time the rate will iterate
for (int j = sCountRate;j <= n; j++){
//displays first column interest rate
System.out.printf("\n %1.3f",startRate);
//startCount is the starting year
//ending year is the last term in years entered by user
//yearsCounter determines the amount of time it will increment (5 in this case)
for (int i = startCount; i <= endingYear;i = i + yearCounter){
//calculates loan payment
totalPayment = calculateLoanPayment(startRate, loanAmount, startCount);
System.out.printf("\t %.2f ", totalPayment);
}
//starting interest rate is incremented by .25 after every iteration
startRate += TF_INCREMENTS;
}
}
【问题讨论】:
-
什么语言?爪哇?
-
是的,我正在使用 java
标签: java for-loop multiple-columns