Case (a recursive machine) factorial

package com.ethjava;

The first example of recursion //
//n!=n*n-1*n-2*...*1;
public class jiecheng {
    public static void main(String[] args) {
        getJieChrng (5);


    }
    public static int getJieChrng(int n) {
        if (n == 0 || n == 1) {
            return 1;
        } else {
            // At this recursive
            int sum = n * getJieChrng(n - 1);
            System.out.println(sum);
            return sum;
        }
    }
    //2
    //6
    //24
    //120
}
Published 45 original articles · won praise 8 · views 5857

Guess you like

Origin blog.csdn.net/wenyunick/article/details/103561797