Site icon WebArtDeveloper

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

https://youtu.be/ZfytLJ58rA8

Exit mobile version