【发布时间】:2014-06-18 16:13:34
【问题描述】:
问题是:
Complete the method occursMoreTimes based on the requirements in its comment.
/**
*Returns true if the number of times val1 occurs in the array is strictly greater
*than the number of times val2 occurs in the array. Otherwise, return false.
*If you wish, you can call the findNumberOf method you wrote above.
**/
我的回答是这样的:
public boolean occursMoreTimes(int[] arr, int val1, int val2){
if(findNumberOf(arr, val1) > findNumberOf(arr, val2)){
return true
}
else {return false;
}
}
但是答案键为我在 if 语句中编写的方法调用声明了一个 int,如下所示:
public boolean occursMoreTimes(int[] arr, int val1, int val2){
int countVal1 = findNumberOf(arr, val1);
int countVal2 = findNumberOf(arr, val2);
if(countVal1 > countVal2){
return true
}
else {return false;
}
}
我的回答可以吗?将方法调用声明为 int 是否有优势?
【问题讨论】: