递归格式模板

 

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的内存图

 

posted @ 2018-12-19 21:20  乐丶Sir  阅读(596)  评论(0编辑  收藏  举报