Q:

Write a method that calculates the factorial of a given number

0

Write a method that calculates the factorial of a given number.
Factorial is the product of all positive integers less than or equal to n. For example, factorial(4) = 4x3x2x1 = 24.
TIP: To make it more interesting, try to do it recursively.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public Integer factorial(Integer n) {
int factorial = n;
for (int j = n - 1; j > 0; j--) {
    factorial = factorial * j;
}
return factorial;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now