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
public static void main(String agr)
Scanner in = new Scanner(System.in);
System.out.println("Enter any number : ");
num = in.nextInt();
for(int i=num-1; i>0; i--)
num *= i;
System.out.println("Factorial of "+cpy+" is "+num);
Enter any number :
Factorial of 5 is 120
Connect with us on following platforms
PRACTICALS/PRACTICE PROGRAM IN Java