阶乘 Java实现

public class Demo{

    public static void main(String[] args) {
        for (int i = 1; i <= 10; i++) {
            System.out.printf("%d!\t = \t%d\n", i, factorial(i));
        }
    }

    public static long factorial(long n) {
        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * factorial(n - 1);
        }
    }

}

猜你喜欢

转载自blog.csdn.net/shu_ze/article/details/80427552
今日推荐