我對編程非常陌生,在主要方法中顯示變量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);
}
}
}
'顯示變量有些麻煩' - 它有什麼樣的麻煩?你可以再詳細一點嗎? – sandrstar