Closed. This question needs details or clarity。它当前不接受答案。
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
6年前关闭。
我对编程很陌生,在我的主要方法中显示可变的monthlyPayment时遇到了一些麻烦;我认为这与先前的方法有关。这是每月付款计算器。
它需要3个参数并返回一个double。
这是您调用
您没有向其发送任何参数。您甚至都不包含
您需要这样做:
注意:您仍然可能无法获得预期的结果。这将汇总
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
6年前关闭。
我对编程很陌生,在我的主要方法中显示可变的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);
}
}
}
最佳答案
这是您的monthlyPayment
方法:
public static double monthlyPayment(double amountBorrowed, int loanLength, int percentage)
它需要3个参数并返回一个double。
这是您调用
monthlyPayment
方法的方式:System.out.println(i + monthlyPayment);
您没有向其发送任何参数。您甚至都不包含
()
。您的编译器应该在抱怨。您需要这样做:
System.out.println(i + monthlyPayment(amountBorrowed, loanLength, percentage));
注意:您仍然可能无法获得预期的结果。这将汇总
i
和您对monthlyPayment
的调用结果,然后打印出来。您可能想要这样的东西:System.out.println("Month " + i + " payment: " + monthlyPayment(amountBorrowed, loanLength, percentage));
关于java - 无法显示变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19697066/
10-10 13:08