Table of Contents
Java program to find factorial of a number
To find factorial we need to multiply the number by each and every number below.
E.g. Factorial of 5 is 5*4*3*2*1 = 120.
Following is the simple Java program to find and print factorial of a number.
Basic Factorial program in Java
import java.util.*;
class Factorial
{
//itvoyagers.in
public static void main(String agr[])
{
int num,cpy;
Scanner in = new Scanner(System.in);
System.out.println("Enter any number : ");
num = in.nextInt();
cpy=num;
for(int i=num-1; i>0; i--)
{
num *= i;
}
System.out.println("Factorial of "+cpy+" is "+num);
}
//itvoyagers.in
}
Output :
Enter any number :
5
Factorial of 5 is 120
PRACTICALS/PRACTICE PROGRAM IN Java
CHECKOUT OTHER RELATED TOPICS
We are aiming to explain all concepts of Java in easiest terms as possible.

ITVoyagers
Author