Find the factorial - Java Program

Q. Find the Factorial of the given number.

Answer:

Factorial is the basically the product of an integer and all the integer below it, e.g. factorial five (5!) is equal to 120.
In this example, we calculate the factorial of the given number.

Factorial.java

class Factorial
{
        public static void main(String[] args)
        {
                int number = 6;
                int fact = 1;
                for (int i=1; i<= number; i++ )
                {
                        fact = fact *i;
                }
                System.out.println("Factorial of "+number+" is: "+fact);
        }
}


Output:

factorial