私はプログラミングに非常に慣れていないため、メインメソッドで変数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);
}
}
}