The factorial function of is the product of integers greater than or equal to .

It can be recursively defined as .

As a Java method:

public static int factorial(int n) {
	if (n <= 0) return 1;
	return n * factorial(n - 1);
}

Iterative solution:

public static int factorial(int n) {
	int result = 1;
 
	for (int i=1;i<=n;i++) {
		result *= i;
	}
 
	return result;
}