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 

Watch it on YouTube:

That’s all about  this topic Java program to find factorial of a number
If you have any feedback or suggestion please feel free to drop in blow comment box. 

Leave a Reply

Your email address will not be published. Required fields are marked *