What causes error "error: '.class' expected"?

What causes error "error: '.class' expected"?

请帮我解决这些错误。
这些是我在执行下面的 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);
  }
}

使用不带参数的函数,因为你的函数什么都不做。

public class Deposit
{
  //Main method
  public static void main(String[] args)
  {
    double results=presentValue();
    ... // same code
  }

  public static double presentValue()
  {
    double f,r;
    int n;
    ... // same code
  }
}

无论何时调用方法,都不要在方法的参数中提及数据类型。

您的错误可以通过更改方法调用行来解决,

确保您直接将值作为参数传递,或者在变量中声明这些值,如下所示。

double f = 1.0d; // Just for Example
double r = 2.0d; // Just for Example
int n = 1; // Just assuming

//Calling the method
double results = presentValue(f, r ,n);