基于用户输入的Java贷款计算器嵌套for循环
任务是根据用户输入的贷款支付最小年数和最大年数、贷款金额、最小和最大百分比以及用户给定的递增值以及利率和年数创建贷款计算器。 所需的输出应如下所示: 原则:275 000美元 还款年限:10年 每月利息 差饷基于用户输入的Java贷款计算器嵌套for循环,java,loops,for-loop,nested,calculator,Java,Loops,For Loop,Nested,Calculator,任务是根据用户输入的贷款支付最小年数和最大年数、贷款金额、最小和最大百分比以及用户给定的递增值以及利率和年数创建贷款计算器。 所需的输出应如下所示: 原则:275 000美元 还款年限:10年 每月利息 差饷 6.25 3087.7 6.75 3157.66 7.25 3228.53 原则:275 000美元 还款年限:15年 每月利息 差饷 6.25 2357.91 6.75 2433.5 7.25 2510.37 原则:275 000美元 还款年限:20年 每月利息 差饷 6.25 2
6.25 3087.7 6.75 3157.66 7.25 3228.53 原则:275 000美元 还款年限:15年 每月利息 差饷
6.25 2357.91 6.75 2433.5 7.25 2510.37 原则:275 000美元 还款年限:20年 每月利息 差饷
6.25 2010.05 6.75 2091.0 7.252173.53 请帮我修正错误。谢谢
public static void main(String[] args){
Scanner console = new Scanner (System.in);
System.out.println("This program computes monthly " + "mortgage payments.");
System.out.print("Enter the loan amount: ");
double loan = console.nextDouble();
System.out.print("Enter the starting number of years to repay the loan: ");
int startingYears = console.nextInt();
System.out.print("Enter the ending number of years to repay the loan: ");
int endingYears = console.nextInt();
System.out.print("Enter the years increment between tables: ");
int incrementYears = console.nextInt();
System.out.print("Enter the starting loan yearly interest rate, %: ");
double startingRate = console.nextDouble();
System.out.print("Enter the ending loan yearly interest rate, %: ");
double endingRate = console.nextDouble();
System.out.print("Enter the increment interest rate, %: ");
double incrementRate = console.nextDouble();
System.out.println();
System.out.println("Principle: $" + (double) loan);
System.out.printf("Years to repay: %d\n", startingYears);
System.out.println("-------- -------");
double payment;
System.out.println("Rate\tPayment");
for (int j = startingYears; j <= endingYears; incrementYears++) {
for (double i = startingRate; i <= endingRate; incrementRate++){
int n = 12 * startingYears;
double c = startingRate / 12.0 / 100.0;
payment = loan * c * Math.pow(1 + c, n) / (Math.pow(1 +c, n) - 1);
System.out.println(i + " " + payment);
// System.out.println(round2(startingRate) + "\t" + round2(payment));
startingYears += incrementYears;
}
}
}
}
publicstaticvoidmain(字符串[]args){
扫描仪控制台=新扫描仪(System.in);
System.out.println(“此程序计算每月”+“抵押付款”);
系统输出打印(“输入贷款金额:”);
double loan=console.nextDouble();
System.out.print(“输入偿还贷款的起始年数:”);
int startingYears=console.nextInt();
System.out.print(“输入偿还贷款的期末年数:”);
int endingYears=console.nextInt();
System.out.print(“输入表格之间的年增量:”);
int incrementYears=console.nextInt();
系统输出打印(“输入起始贷款年利率,%:”;
双启动速率=console.nextDouble();
系统输出打印(“输入期末贷款年利率,%:”;
double-endingRate=console.nextDouble();
系统输出打印(“输入增量利率,%:”;
double incrementRate=console.nextDouble();
System.out.println();
System.out.println(“原则:$”+(双)贷款);
System.out.printf(“偿还年份:%d\n”,起始年份);
System.out.println(“-----------------”);
双倍支付;
System.out.println(“费率\付款”);
对于(int j=开始年份;j
对于(int j=开始年份;j
对于(int j=startingYears;j我不是100%理解这个建议。我需要添加I+=incrementYears吗?对于(int j=startingYears;j更新了解决方案。在System.out.println(“原则:$”+(双)贷款)之后替换所有内容;
在您的解决方案中使用上述代码片段。我不是100%理解该建议。我是否需要添加I+=incrementYears?for(int j=startingYears;j更新了解决方案。在System.out.println(“原则:$”+(双)贷款)之后替换所有内容;
在您的解决方案中使用上述代码段。如何增加两个计数器?如何增加两个计数器?
System.out.println("Principle: $" + (double) loan);
for (int j = startingYears; j <= endingYears; j+=incrementYears) {
System.out.printf("Years to repay: %d\n", j);
System.out.println("-------- -------");
System.out.println("Rate\tPayment");
for (double i = startingRate; i <= endingRate; i+=incrementRate){
int n = 12 * j;
double c = i / 12.0 / 100.0;
double payment = loan * c * Math.pow(1 + c, n) / (Math.pow(1 + c, n) - 1);
System.out.println(i + "\t" + payment);
}
System.out.println();
}