這個問題在這里已經有了答案: “錯誤:'.class' 預期”是什么意思,我該如何解決 (1 個回答) 14 小時前關閉。
請幫我解決這些錯誤。
這些是我在執行下面的 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);
}
}
uj5u.com熱心網友回復:
使用沒有引數的函式,因為你的函式什么都不做。
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
}
}
uj5u.com熱心網友回復:
錯誤主要是語法錯誤。您的代碼不是有效的 Java。
特別是這一行不是有效的 java 并且被錯誤標記。
double results=presentValue(double f, double r ,int n);
您也無法在回傳后執行代碼。
//Returning the value to the present value method
return p;
System.exit(0);
請自行檢查其他錯誤。
uj5u.com熱心網友回復:
無論何時呼叫方法,都不要在方法的引數中提及資料型別。
您的錯誤可以通過更改方法呼叫行來解決,
確保您將值直接作為引數傳遞,或者在變數中宣告這些值,如下所示。
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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/349503.html
