public class FindMax {
static int max;
public static int compare(int a, int b){
if(a > b){
return a;
}
return b;
}
public static int findMax(int[] A, int endIndex, int addtion){
if(endIndex == 1){
max = compare(A[0],A[1]);
return max;
}else{
return compare(findMax(A, --endIndex, --addtion),A[--addtion]);
}
}
public static void main(String[] args){
int[] A = {43,6,4,2,76,345,77,9,0};
System.out.println(findMax(A, A.length - 2, A.length - 1));
}
}
使用递归求数组最大值(java实现)
最新推荐文章于 2023-01-18 15:04:51 发布