gpt4 book ai didi

java - 无法显示变量

转载 作者:行者123 更新时间:2023-11-29 07:53:16 25 4
gpt4 key购买 nike

<分区>

我是编程新手,在我的主要方法中显示变量 monthlyPayment 时遇到了一些问题;我认为这与以前的方法有关。这是一个月供计算器。

import java.util.Scanner;
public class assignment8 {

public static double pow(double a, int b) {
double ans = 1;
if (b < 0) {
for (int i = 0; i < -b; i++) {
ans *= 1/a;
}
}
return ans;
}

public static double monthlyPayment(double amountBorrowed, int loanLength, int percentage) {
double monthlyPayment;
double P = amountBorrowed;
double N = 12 * loanLength;
double r = (percentage / 100) / 12;
monthlyPayment = (r * P) / (1 - Math.pow((1 + r) , -N ));
return monthlyPayment;
}

public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);

System.out.print("Enter the amount borrowed: $");
double amountBorrowed = kbd.nextDouble();

System.out.print("Enter the interest rate: ");
int interestRate = kbd.nextInt();

System.out.print("Enter the minimum length of the loan: ");
int minLoanLength = kbd.nextInt();

System.out.print("Enter the maximum length of the loan: ");
int maxLoanLength = kbd.nextInt();

while (maxLoanLength < minLoanLength) {
System.out.print("Enter the maximum legth og the loan: ");
maxLoanLength = kbd.nextInt();
}
for (int i = minLoanLength; i <= maxLoanLength; i++) {

System.out.println(i + monthlyPayment);
}
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com