Tuesday, November 22, 2016

Write a JAVA program give example for command line arguments.

Aim: Write a JAVA program give example for command line arguments.

Program:

class Factorial
{  
public static void main(String args[])  
{    
 int n,i,fact=1; 
 n=Integer.parseInt(args[0]);
if(n==0||n==1)
fact=1;
else
{
 for(i=1;i<=n;i++)
fact*=i; 
}
 System.out.print("factorial("+n+")= "+fact);    
 }
}  

Output:


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home