Gubbas Digi Communications

Gubbas Digi Communications

Factorial using Recursion

FACTORIAL USING RECURSION

It is the process of having a method continually call itself until a defined point of termination.
class Factorial
{
public int fact(int n)
{

if(n==0)
{
return 1;
}
else

{
return n*fact(n-1);
}
}

public static void main(String[] args)
{
Factorial f=new Factorial();
System.out.println("The factorial is:"+f.fact(5));
}
}
OUTPUT:

The factorial is: 120




No comments:

Post a Comment