Calculate Factorial of Any Given Number In JAVA

This Java programming tutorial will teach you the methods for writing program to calculate factorial of any given number.

/*
Factorial Example In JAVA
This Java Factorial Example shows how to calculate factorial of
a given number using Java.
*/

public class FactorialNum {

public static void main(String[] args) {

int num =7;

/*
* Factorial of any number is !n.
* For example, factorial of 6 is 6*5*4*3*2*1.
*/

int fact = num;

for(int i =(num – 1); i > 1; i–)
{
fact = fact * i;
}

System.out.println(“Factorial of a number is ” + fact );
}
}

/*
Output of the Factorial program would be
Factorial of a number is 5040
*/