Custom Search

Saturday, 25 August 2012

Java Program to find Factorial Using Recursion, Write a program in Java language for an an application to find factorial using recursion


Java Program to find Factorial Using Recursion, Write a program in Java language for an an application to find factorial using recursion

Program
class facto
{
public static void main(String args[])
{
int no,f;
no = Integer.parseInt(args[0]);
Logic L=new Logic();
f=L.fact(no);
System.out.println("Factorial of " + no + " is " + f);
}
}
class Logic
{
public int fact(int n)
{
if(n==1)
return 1;
else
{
return n*fact(n-1); //Recursion
}

}
}

No comments:

Post a Comment

Laptops