首页 > 技术文章 > 递归格式模板

l666 2018-12-19 21:20 原文

 

public class test{
        public static int f1(int n){
            if(n==1) return 1;
            return f1(n-1)+n;
        }
    public static void main(String[] args){
            System.out.println(f1(100));
    }
}

  上面为使用递归方法计算1+100的代码

 

  递归 1+5的内存图

 

推荐阅读