递归求阶乘的和

import java.util.Scanner;

/**
 * @author HelloWorld
 * @create 2021-04-07-11:17
 * @email 154803771@qq.com
 */
public class Test13 {
    //递归求阶乘的和
    public static void main(String[] args) {
        System.out.print("Input n: ");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(mut(n));
    }

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

上一篇:【LeetCode】位运算 bit manipulation(共32题)


下一篇:表单进阶