# Java program to find factorial of a number

By | August 10, 2018

In this post we will learn about Java program to find factorial of a number.

Before Witting java program let’s understand what is Factorial number?

What is Factorial Number?

In mathematics language, we can say that the factorial of a non-negative integer n, denoted by n! is the product or  multiplication of all positive integers less than or equal to n.

For example, 5 ! = 5 × 4 × 3 × 2 × 1 = 120.

The factorial of a negative number doesn’t exist. And the factorial of 0 is 1

We will solve this problem statement using below 2 approaches:

1. Using for loop
2. Using recursion

Example 1:

Using for loop

Below  source code of the Java Program reads number from the user and finds factorial value using for loop

Example 2:

Using recursion

Below  source code of the Java Program reads number from the user and finds factorial value With using Recursion.

I have tested  both programs for few inputs as below. You may check for other input as well