Question: Write a program that prints a factorial to the screen. The factorial ofa number is found by multiplying itself by all positive integers less than


Write a program that prints a factorial to the screen. The factorial ofa number is found by multiplying itself by all positive integers less than it (excluding 0). For example, 4 factorial, written as 4!, can be computed as follows: 4! == 4 * 3 * Z * 1 == 24 After taking user input for the factorial they want to nd, print out the factorial to the console. You will need to complete the computeFactorial method and call it from your main method. Pass the user input as a parameter to the computeFactorial method. Use the variable result in the starter code to hold the factorial in the computeFactorial method. Remember to use a for loop! Java does not have a built in factorial operator. Example Output: Enter an integer 4 The factorial of 4 is 24 1 public class Factorial 2*{ 3 // This variable will hold the factorial answer when you print 4 // computeFactorial method. 5 private static int result = 1; 6 7 3. public static void main(String args) { 9 // Create a scanner object to hold user input 10 11 // Prompt the user to enter an integer for the number they1 12 // factorial of. 13 14 // Take the input and store it in a variable the will be us 15 // the computeFactorial method. 16 17 // Call computeFactorial with your var passed as the argume 18 } 19 20 public static void computeFactorialC) 21. { 22 // Commplete the method for computing the factorial here. B 23 // a print statement and use the variable result to hold th 24 // result. 25 } 26 } 27
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
