class rfactorial
{
public static void main(String args[])
{
int num=Integer.parseInt(args[0]);
int fact;
recursion r1=new recursion();
fact=r1.rec(num);
System.out.println("The factorial for "+num+" is = "+fact);
}
}
class recursion
{
public int rec(int a)
{
int f;
if(a==1 || a==0)
{
return(1);
}
else
{
f=a*rec(a-1);
return(f);
}
}
}
No comments:
Post a Comment