Question: Problem #1 Factorial Problem Using Loops Write a program that can solve the factorial problem. Your class should have two methods: The main method A

Problem #1 Factorial Problem Using Loops Write a program that can solve the factorial problem.

Your class should have two methods: The main method A static method called factorial that accepts an int as input and returns an int (the answer) The main method should: Contain a loop with a counter loops from 0 to 5 (inclusive) For each counter, call factorial. Print the counter and the result returned of the factorial. The factorial method should: Calculate the answer for the factorial. Use a loop to calculate the answer. No print statements are needed in this method, but you may want to print along the way to help you write and debug the program. Recall the rules for factorial: - The factorial of 0 is 1. Just a general rule, no multiplication needed. - The factorial of 1 is 1. Just a general rule, no multiplication needed. - The factorial of 2 is 2 * 1 = 2 - The factorial of 3 is 3 * 2 * 1 = 6 - The factorial of 4 is 4 * 3 * 2 * 1 = 24 - The factorial of 5 is 5 * 4 * 3 * 2 * 1 = 120

Your output should simply be the following: 0! is 1 1! is 1 2! is 2 3! is 6 4! is 24 5! is 120

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!