In this tutorial how to find a Factorial of a number using Recursion in Core Java is shown.
Code:
Recursion.java
class Factorial
{
static int fact(int i)
{
if(i>0)
{
return i*fact(i-1);
}
else
{
return 1;
}
}
public static void main(String arg[])
{
int no=Integer.parseInt(arg[0]);
System.out.println(“Factorial of “+no+” is “+fact(no));
}
}