source file name: Factorial.java
class Factorial
{
public static void main(String args[])
{
int no=Integer.parseInt(args[0]);
int fact=1;
for(int i=1;i<=no;i++)
fact=fact*i;
System.out.println("The Factorial of " + no + " is "+fact);
}
}
output:
D:\JavaPrograms\CmdPrograms>javac Factorial.java
D:\JavaPrograms\CmdPrograms>java Factorial 5
The Factorial of 5 is 120
D:\JavaPrograms\CmdPrograms>java Factorial 8
The Factorial of 8 is 40320
D:\JavaPrograms\CmdPrograms>java Factorial 10
The Factorial of 10 is 3628800
0 Comments
Post a Comment