Showing posts with label Factorial Number in java. Show all posts
Showing posts with label Factorial Number in java. Show all posts

Factorial Number in Java

 

package test;

 

public class FactorialNumber {

 

     public static void main(String[] args) {

         //1

         //1x2 2!

         //1x2x3 3!

         int givenNum = 5;

         int calculatedNum = 1;

         for (int i = 0; i < givenNum; i++) {

              calculatedNum = calculatedNum * (givenNum - i);

         }

         System.out.println("The factorical number of the given number = " + calculatedNum);

     }

 

}

Output:

The factorical number of the given number = 120