Complete the method, factorial(). The method takes in a non-negative integer, n.
ID: 3753762 • Letter: C
Question
Complete the method, factorial(). The method takes in a non-negative integer, n. It should use a loop to compute and return the factorial of n, n!, as an integer. The factorial of n, n!, is defined as the product of the integers from 1 to n:
n! = n * (n-1) * (n-2) * ... * 3 * 2 * 1
Note: in math we define 0! = 1
You may assume that n is a non-negative integer.
* Caution: the factorial value grows VERY fast! Just test your method with small values of n
Starter Code:
public class Method {
public static int factorial(int n) {
//TODO: complete this method
}
}