Factorial of a Number in Java
Here, you will get the program code to find the factorial of given number in java programming using while loop.
What is factorial in math?
Factorial is a mathematical term that refers to the product of all positive integers less than or equal to a given number.
For instance, the factorial of 5 is 5 x 4 x 3 x 2 x 1, which equals 120.
Program to Find Factorial of a Number in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | class factorial { public static void main(String str[]) { int num,fact=1,i=1; num=Integer.parseInt(str[0]); while(num>=i) { fact=fact*i; i++; } System.out.println("Factorial of a given no is = "+fact); } } |
Output
Check out our other Java Programming Examples