Java Factorial using recursion example


Java program to find factorial of a number using recursion. This Java method gets and integer number n and returns n factorial using recursion.

//Java factorial using recursion
public double factorial(int n){
    if (n==0)
        return 1;
    else
        return n*(factorial(n-1));
}


How does recursive factorial method work? Here you can see how recursion works to find factorial of a number.


No comments :

Post a Comment