Home >>Java Programs >Factorial Program using recursion in java
In this example, we will see a Java program to find the factorial of any given input number.
Factorial of any number "n" is basically the product of all the positive integers less than the given number. Factorial of n is denoted by n!.
In this program, we will be using recursion to find the factorial of the given number.
Program
class Main
{
static int factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
public static void main(String args[])
{
int i,fact=1;
int number=9;//It is the number to calculate factorial
fact = factorial(number);
System.out.println("Factorial of "+number+" is: "+fact);
}
}