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,
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 } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started