java方法存根错误

时间:2016-11-04 15:46:57

标签: java methods

示例输出:

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

1 个答案:

答案 0 :(得分:0)

您正在使用参数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;
}