java————用递归算法求阶乘

public class TestRecursion {

public static void main(String[] args) {
    int i;
    System.out.println("请输入需要阶乘的一个整数:");
    Scanner scanner = new Scanner(System.in);
    i = scanner.nextInt();
    System.out.println(i + "的阶乘是:" + jc(i));

}

public static int jc(int i) {
    if (i == 0 && i == 1) {
        return 1;
    } else if (i > 0) {

        int result = i * jc(i - 1);
        return result;
    } else {
        return 1;
    }

}

}

    原文作者:递归算法
    原文地址: https://blog.csdn.net/weixin_41615851/article/details/79131029
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞