1. Home
  2. Java
  3. Java Examples
  4. Find Factorial of Number

Find Factorial of Number

Java – Find Factorial of A Given Number

Write a Java program to find a factorial of the given number input by the user.

What is Factorial of Number?

The factorial is represented by the exclamation mark (!). A simple formula to calculate the factorial of a number is

n! = n (n - 1)!

For an example, the factorial of 5 is equivalent to 5 x 4 x 3 x 2 x 1.

Java Program to Find Factorial of a Number

This is a Java program to find the factorial of a Number using for loop. This program prompt user to enter a number and calculate factorial of that number. Then print the factorial of the number.

Compile and run program:

javac FindFactorial.java
java FindFactorial

Result:

Enter a number:
5
The factorial of 5 is 120