/**
* 利用递归的方法来球一个整数数组中的最大值
* 思路就是:递归的求解“数组的第一个元素”与“数组中的其他元素的子数组的最大值”的最大值
* @author Administrator
*
*/
public class Test02 {
public int maxNum(int a[],int begin){
int length= a.length-begin;
if(length==1){
return a[begin];
}
else{
return max(a[begin], maxNum(a,begin+1));
}
}
private int max(int a, int b){
return a>b?a:b;
}
public static void main(String[] args) {
Test02 test02=new Test02();
int num[]={1,3,4,5,6,7,8,9,9,12,34,2,3,4,56,4};
System.out.println(test02.maxNum(num, 0));
}
}
该博客介绍如何使用Java递归方法找到整数数组中的最大值。通过递归求解数组的第一个元素与剩余子数组最大值之间的最大值,实现了高效查找。示例代码中详细展示了递归函数和辅助函数的实现。

4521

被折叠的 条评论
为什么被折叠?



