数据结构(4):图解递归调用机制

    

 

  

package com.Exercise.DataStructure_Algorithm.Recursion;

public class RecursionTest1 {
    public static void main(String[] args) {
        test1(3);
        int res = test2(3);
        System.out.println(res);
    }

    public static void test1(int n){
        if(n > 2){
            test1(n-1);
        }
        System.out.println("n="+n);
    }

    public static int test2(int n){
        if(n == 1){
            return 1;
        }else{
            return test2(n-1) * n;
        }
    }
}

 

 

posted @ 2021-01-07 13:59  飘渺红尘✨  阅读(221)  评论(0编辑  收藏  举报
Title