Problem
You have been given a positive integer . You need to find and print the Factorial of this number. The Factorial of a positive integer refers to the product of all number in the range from to . You can read more about the factorial of a number here.
Input Format:
The first and only line of the input contains a single integer denoting the number whose factorial you need to find.
The first and only line of the input contains a single integer denoting the number whose factorial you need to find.
Output Format
Output a single line denoting the factorial of the number .
Output a single line denoting the factorial of the number .
Sample Input
2
Sample Output
2
Solution
All one needs to do here is to find the product of all the number in the range from to . This can be done by iterating over the entire range from to .
import java.io.*;
import java.util.*;
class example_2
{
static Scanner sc=new Scanner(System.in);
public static void main(String args[]) throws Exception
{
long n=sc.nextLong(),prod=1;
for(long i=1;i<=n;i++)
{
prod=prod*i;
}
System.out.println(prod);
}
}