Write a Program in java to find out the factorial of the number

									

Object:-Write a Program in java to find out the factorial of the number

import java.util.Scanner; 

class Factorial
{
    public static void main(String...s)
    {
        int n,fac=1,i;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number: ");
        n = sc.nextInt();        
        for(i=1;i<=n;i++)
            fac*=i;        
        System.out.println("nFactorial = "+fac);   
        sc.close();
    }
}

Output

Enter a number: 5
Factorial=120
 

Explanation

We can find factorial of any number by multiplying it with all the numbers below it.

For example, factorial of 5 is 5*4*3*2*1 = 120