In: Computer Science
Replace <missing value> and <missing code> with your answers. Your code should compute the factorial of n. For example, if n = 5, your code should compute the following 5 * 4 * 3 * 2 * 1 (which is 120).
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int factorial = <missing value>;
<missing code>
System.out.println("factorial = " + factorial);
If you have any doubts, please give me comment...
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int factorial = 1;
for (int i = n; i > 0; i--) {
factorial *= i;
}
System.out.println("factorial = " + factorial);
}
}