Java How To -Calculate Factorial of a Number
How To Calculate Factorial of a Number
Use a loop to calculate the factorial of a given number:
Example
int n = 5;int fact = 1;for (int i = 1; i <= n; i++) { fact *= i;}System.out.println("Factorial of " + n + " is " + fact);// Output: Factorial of 5 is 120
