【发布时间】:2017-03-30 18:38:57
【问题描述】:
我需要找出如何在数组中找到最大值,小于数组的第一个索引。到目前为止,我只知道如何在我的数组中找到最大值(如下所示),但我只需要帮助从我的方法返回小于数组中第一个数字的最大值。
public static int findMaxOfLessThanFirst(int[] numbers, int startIndex, int endIndex, int firstNumber) {
if (endIndex == startIndex) {
return numbers[endIndex];
}
else {
int max = findMaxOfLessThanFirst(numbers, startIndex, endIndex - 1, firstNumber); //Calling method using recursion.
if (max < numbers[endIndex]) {
return numbers[endIndex];
}
else {
return max;
}
}
}
【问题讨论】:
-
提示:换句话说,所有大于或等于第一个的数字都不算数,就好像它们不存在一样。