gpt4 book ai didi

java方法 stub 错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:20 25 4
gpt4 key购买 nike

示例输出:

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);

最佳答案

您正在使用参数computeAvg(userNum1, userNum2)调用函数computeAvg。在函数声明中,您需要提供这些参数:

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

//do something with userNum1 and userNum2 here

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

关于java方法 stub 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40426774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com