递归格式模板

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

猜你喜欢

转载自www.cnblogs.com/l666/p/10146172.html