递归阶乘

    技术2025-04-24  12

    public static void main(String[] args) { System.out.println(factorial(5)); System.out.println(new Serie().fact.apply(5)); System.out.println(factStatic.apply(5));

    } private static int factorial(int x){ if(x == 1 || x==0) return 1; return x*factorial(x-1); } private UnaryOperator<Integer> fact = x->((x==1 || x==0)? 1 : x * this.fact.apply(x-1)); private static UnaryOperator<Integer> factStatic = x->((x==1 || x==0)? 1 : x * Serie.factStatic.apply(x-1));
    Processed: 0.008, SQL: 9