← Unit 2 · all exercises
Saved in this browser only

Factorial

Return the product of every whole number from 1 up to n. 5 gives 120. The factorial of 0 is 1.

int factorial(int n)

Solution.java
Loading editor…
Results

Examples

  • factorial(5) → 120
  • factorial(3) → 6

There are also 4 hidden tests you can't see. Solve the problem, not the examples.