Factorial Program In Java
Chapter:
Miscellaneous
Last Updated:
18-07-2016 04:39:26 UTC
Program:
/* ............... START ............... */
public class JavaFactorialExample {
public static void main(String[] args) {
int num = 8;
int factorial = num;
for (int i = (num - 1); i > 1; i--) {
factorial = factorial * i;
}
System.out.println("Factorial of a number is " + factorial);
}
}
/* ............... END ............... */
Output
Factorial of a number is 40320
Notes:
-
Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!.
- For example, factorial of 4 is 4*3*2*1.
Tags
Armstrong Number, Java