Java Tencent interview questions-there is a disorderly array, find the maximum value, pay attention to not allow loops and functions

Find the maximum value under the condition that no loop can be used and the function cannot be used!

 

 

   //验证可行 
    public static void main(String[] args) {
        int val=getMax(are.length-1,are,0);
        System.out.println("this max"+val);
    }

    private static int[] are={1,7,2,6,100,7};//这里可以随便写

    private static int getMax(int index,int[] are,int val){
        if (index == 0){
            return val;
        }
        int max=val > are[index] ? val:are[index];
        index--;
        return tt.getMax(index,are,max);
    }

Guess you like

Origin blog.csdn.net/bbs11007/article/details/101386581