Learn Programming and technology with ease @ developerpublish.com

HomeJavaJava Program to Find Factorial of a Number Using Recursion

# Java Program to Find Factorial of a Number Using Recursion

In this Java program, you’ll learn how to Find Factorial of a Number Using Recursion using the Java programming language.

## How to Find Factorial of a Number Using Recursion in JAVA?

### Example 1:

```public class Main
{
public static void main(String[] args)
{
int num = 5;
long factorial = multiplyNumbers(num);
System.out.println("Factorial of " + num + " = " + factorial);
}
public static long multiplyNumbers(int num)
{
if (num >= 1)
return num * multiplyNumbers(num - 1);
else
return 1;
}
}```

## OUTPUT

`Factorial of 5 = 120`

From the main() function the multiplyNumbers() is called and an argument 5 is passed

To get the results 5 is multiplied to the results of multiplynumbers() where 4(num-1) is passed. It is called as recursive call.

The recursion will end when the num is less than 1,

Share:

### You May Also Like

Java is a popular programming language that is used to develop a wide range of applications. If you are a...
• Java
• March 6, 2023