class Factorial
{
public static void main(String[] arg)
{
int[] num=new int[10];
if(arg.length==0)
{
System.out.println("No Command Line argument passed.");
return;
}
for(int i=0;i<arg.length;i++)
num[i]=Integer.parseInt(arg[i]);
for(int i=0;i<arg.length;i++)
{
int fact=1;
for(int j=1;j<=num[i];j++)
fact *=j;
System.out.println("The factorial of "+arg[i]+" is : "+fact);
}
}
}
Output
C:\Users\Jaisha\Desktop\Java>javac Factorial.java
C:\Users\Jaisha\Desktop\Java>java Factorial
No Command Line argument passed.
C:\Users\Jaisha\Desktop\Java>java Factorial 5 6
The factorial of 5 is : 120
The factorial of 6 is : 720
{
public static void main(String[] arg)
{
int[] num=new int[10];
if(arg.length==0)
{
System.out.println("No Command Line argument passed.");
return;
}
for(int i=0;i<arg.length;i++)
num[i]=Integer.parseInt(arg[i]);
for(int i=0;i<arg.length;i++)
{
int fact=1;
for(int j=1;j<=num[i];j++)
fact *=j;
System.out.println("The factorial of "+arg[i]+" is : "+fact);
}
}
}
Output
C:\Users\Jaisha\Desktop\Java>javac Factorial.java
C:\Users\Jaisha\Desktop\Java>java Factorial
No Command Line argument passed.
C:\Users\Jaisha\Desktop\Java>java Factorial 5 6
The factorial of 5 is : 120
The factorial of 6 is : 720
No comments:
Post a Comment