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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!