How to Create a Program to Find a Factorial of a Number using Recursion in Core Java

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));
}
}

Add a Comment

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