06、递归讲解

在这里插入图片描述

package com.wzt.www.method;

/**
 * @author WZT
 * @create 2021-03-26 10:56
 */
public class Demo05 {
    
    
    public static void main(String[] args) {
    
    
        Demo05 test = new Demo05();
        Long result = test.f(33L);
        System.out.println(result);
    }
    public Long f(Long n){
    
    
        if (n==1){
    
    
            return (long)1L;
        }else {
    
    
            return n*f(n-1);
        }
    }
}

输出

3400198294675128320

Process finished with exit code 0

注意点

  • 递归不要太多次容易造成栈溢出

猜你喜欢

转载自blog.csdn.net/weixin_45809838/article/details/115232914