Header Ads

Find the factorial of a nunber (Using command line)

In this program, input will be taken from the command line. So you have to pass the input as command line argument.



class Fact
{
    static double factorial(double n)
    {
        if(n==1 || n==0)
        {
            return(1);
        }
        else
        {
            return(n*factorial(n-1));
        }
    }
public static void main(String[] args)
{
    double a=Double.parseDouble(args[0]);
    double f=Fact.factorial(a);
    System.out.println("The factorial of "+ a + " is "+ f );  
}
}

No comments

Powered by Blogger.