帮助理解递归,以及递归返回值的处理

public class digui {
    private static int big = 10;
    public static Integer rand(){
        Random random = new Random();
        int i = random.nextInt(100);
        return i;
    }
    public static Integer digui(){
        Integer s = null;
        Integer rand = rand();
        Integer a = 0;
        if(rand%3==0){
            s = rand;
            return s;
        }else if(rand%3!=0){
            if(big>0){//不包含0
                big--;

                a = digui();
                System.out.println(a);
            }
        }else{
            a = 100000;
            return a;
        }
        System.out.println(s);
        return a;
    }

    @Test
    public void invoke(){
        Integer digui = digui();
        System.out.println(digui);
    }
}

能够很好的帮助理解递归和java的底层——压栈和弹栈的流程

你可能感兴趣的:(java)