Question
Given a positive number n, the factorial of that number, denoted n!, is equal to 1 x 2 x ... (n - 1) x n.
Given a positive number n, the factorial of that number, denoted n!, is equal to 1 x 2 x ... (n - 1) x n. Assuming that n is greater than zero and less than 12, complete the program named Factorial below, so that it computes the value of n! for any positive n less than 12.
Input: n, the integer value for which n! is to be computed. Output: n! -- the factorial of n
Complete the following file:
Factorial.java
import java.util.Scanner;
/** Computes n! = 1 x 2 x ... (n - 1) x n, given n. We assume n is greater than zero and less than 12.
Input: n, the integer value for which n! is to be computed. Output: n! -- the factorial of n */ public class Factorial { public static void main(String[] args) { // Read value for n Scanner in = new Scanner(System.in); int n = in.nextInt();
// your work here
System.out.println(factorial); } }
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