不用循环找数组最大值

https://www.xuebuyuan.com/2031226.html

/**
 * @author ZTX
 * 不用循环怎么求出数组的最大值?
 * 本方法使用递归求解的
 * 2013年11月2日17:50:01
 */
public class test {
     public static int i=0;
     public static int max =0;
     public static int len =0;

     public static void main(String[] args) {
         int a[]={1,2,4,6,2,8,3};
         len=a.length-1;
         find(max, i,a);
        }
     public static void  find(int max,int i,int a[]){
         if (a[i]>max)  max=a[i];
         if (i<len){
             i++;
             find(max,i,a);
         }else
        System.out.println(max); 
     }
}

猜你喜欢

转载自blog.csdn.net/junjunba2689/article/details/82496430