Java recursion and bounded factorial
Each recursive call gets its own parameter and waits for the smaller call's result. factorial(0) returns one and stops descent.
Java
class Main {
static long factorial(int n) {
if (n < 0 || n > 20) throw new IllegalArgumentException("use 0 through 20");
if (n == 0) return 1;
return n * factorial(n - 1);
}
public static void main(String[] args) {
System.out.println(factorial(4));
if (factorial(0) != 1) throw new AssertionError("base");
}
}