Tutorials

Java Basic Programs


Java Factorial


In this tutorial, our task is:

  • to find the factorial of the given number
  • print the factorial.

Example:

Given number: 7

factorial: 5040

 

Given below is the java program to find factorial of the given number.


public class factorial {

      public static void main(String[] args) {

            int num = 7;
            int fact = 1;
           
            for(int i= num; i>0; i--){

                  fact = fact*i;

            }

            System.out.println(fact);

      } 

}

 OUTPUT:

5040

 



Please Share this page
Views : 31