2016-11-04 68 views
1

輸出示例:Java方法存根錯誤

FIXME:完成getUserNum()

FIXME:完成getUserNum()

FIXME:完成computeAvg()

平均:-1

代碼我有:

public class MthdStubsStatistics { 

public static int getUserNum() { 

System.out.println("FIXME: Finish getUserNum()"); 
return -1; 

} 

public static Integer computeAvg(){ 

System.out.println("FIXME: Finish computeAvg()"); 
return -1; 
} 

public static void main() { 
    int userNum1 = 0; 
    int userNum2 = 0; 
    int avgResult = 0; 

    userNum1 = getUserNum(); 
    userNum2 = getUserNum(); 

    avgResult = computeAvg(userNum1, userNum2); 

    System.out.println("Avg: " + avgResult); 

    return; 
    } 
} 

我遇到的問題是computeavg方法是給我這個錯誤:

MthdStubsStatistics.java:23: computeAvg() in MthdStubsStatistics cannot be applied to (int,int) avgResult = computeAvg(userNum1, userNum2); 
+3

'computeAvg'不接受任何參數,您不能使用參數調用它。 – Berger

+0

當你遇到你不明白的異常時,嘗試創建一個[mcve]。這將幫助您追蹤到底是什麼問題,並使其他人更容易幫助您解決問題。 –

+0

好,非常感謝 – BMajowicz

回答

0

您調用的函數computeAvg與參數computeAvg(userNum1,userNum2)。在函數聲明中,您需要提供以下參數:

public static Integer computeAvg(int userNum1, int userNum2){ 

//do something with userNum1 and userNum2 here 

System.out.println("FIXME: Finish computeAvg()"); 
return -1; 
}