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

You May Also Like:

How to swap two numbers with or without temporary variable in java
Java Program to Swap two numbers using Bitwise XOR Operator?
How to reverse a number in Java
How to check Armstrong number java program
Java Program to Calculate the Power of a Number
Check whether a number is prime or not
Java Program to displaying prime numbers
Fibonacci series using iterative and recursive approach java program
Find largest and second largest number in the given Array
Java program to Remove Duplicate Elements From an Array
Find common elements between two Arrays
Find largest and smallest number in the given Array
Java Program to find duplicate elements in an Array
Count number of words in a string in java
How would you check if a number is even or odd using bit wise operator in Java?
How can you check if the given number is power of 2?
How to check if String is number in java ?

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.