You are here: Home / Topics / Program for getting Factorial of any number in Java

Program for getting Factorial of any number in Java

Filed under: Java on 2023-08-18 06:45:28

//Program to Calculate the Factorial of the Given Number.

class  FactorialTest
{
public static void main( String args[ ] )
{
 int i, n;
 
 n = 5;

 int f = 1;
 for( i=n ; i>=1 ; i-- )
 {
  f = f * i ;
 }
 System.out.println( "\n The Factorial of " + n + " is = " + f );
}
}


Output:

The Factorial of 5 is = 120

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.