【发布时间】:2016-03-21 19:27:25
【问题描述】:
这是我的代码。
public static void main(String[] args) {
int[] array = {5,3,1,0,4,7};
int smallest = array[0];
System.out.println(smallest(array,smallest));
}
private static int smallest(int[] array, int smallest){
int count = 0;
if(array[count] < smallest){
smallest = array[count];
}
else if(array[count] == array[array.length-1]){
return smallest;
}
count++;
return smallest(array,smallest);
}
}
我需要使用 java 来使用 RECURSION 找到数组中的最小 int,我知道如何使用迭代来找到它,但这是严格的递归。任何帮助都会得到帮助。在我看来,这一行的错误在这里。
--> 返回最小(数组,最小);
【问题讨论】: