【发布时间】:2021-12-19 06:32:42
【问题描述】:
请帮我解决这些错误。
这些是我在执行下面的 java 代码后遇到的错误。
/Deposit.java:15: error: '.class' expected
double results=presentValue(double f, double r ,int n);
^
/Deposit.java:15: error: ';' expected
double results=presentValue(double f, double r ,int n);
^
/Deposit.java:15: error: <identifier> expected
double results=presentValue(double f, double r ,int n);
^
/Deposit.java:15: error: ';' expected
double results=presentValue(double f, double r ,int n);
^
4 errors
import javax.swing.JOptionPane;
/*This program computes a customers present
deposit to make to obtain a desired future
value
*/
public class Deposit
{
//Main method
public static void main(String[] args)
{
//Calling the present value method
double results=presentValue(double f, double r ,int n);
//Displaying the present value
JOptionPane.showMessageDialog(null, "You have to deposit: $" +results);
}
public static double presentValue(double f, double r, int n)
{
//Declaring the input variable
String input;
//Taking inputs from the customer
//Future value
input = JOptionPane.showInputDialog("Enter your desired future value:");
f = Double.parseDouble(input);
//Annual Interest Rate
input = JOptionPane.showInputDialog("Enter the annual interest rate:");
r = Double.parseDouble(input);
//Number of years
input = JOptionPane.showInputDialog("Enter the number of years:");
n = Integer.parseInt(input);
//Calculating the present value the customer has to deposit
double p = f/Math.pow((1+r), n);
//Returning the value to the present value method
return p;
System.exit(0);
}
}
【问题讨论】:
-
double results=presentValue(double f, double r ,int n);你没有在这里传递任何值,
标签: java swing compiler-errors joptionpane