if (x < 0) throw new IllegalArgumentException("x must be >= 0"); if (x <= 1) return 1; // Stop recursing here else return x * factorial(x-1); // Recurse by calling ourselves