Java Program to Find Factorial of a Number

Write a Java program to find factorial of a number.



Source Code
class Factorial {

	public static void main(String[] args) {

		int fact=1,no;
		no = Integer.parseInt(args[0]);
		
		System.out.print("Factorial of "+no+" is ");
		
		while(no > 0) {
			
			fact = fact * no;
			no--;
		}
		System.out.println(fact);
	}
}
Output
C:\>javac Factorial.java
C:\>java Factorial 4
Factorial of 4 is 24





"Coding Hub - Learn to code" app now available on Google Play Store