递归求阶乘数的值

题目:利用递归方法求5!。 

    /*
     * 题目:利用递归方法求5!。 
     */
    public static void main(String[] args) {
        int recFive = getRecursion(5);
        System.out.println(recFive);
    }
    //第i项的值
    public static int getRecursion(int i){
        if (i==1) {
            return 1;
        }
        return getRecursion(i-1)*i;
    }

源码

 

点赞

Leave a Reply

Your email address will not be published. Required fields are marked *