# Factorial Using Recursion In Java

Sharing is healthy !!

Let’s write program using recursion. I would like to give a demo on factorial using recursion in java.

## Factorial

Usually the term factorial is used in permutation and combination. The term factorial is the multiplication of non-negative descending numbers.

### Factorial Example

5! = 5 * 4 * 3 * 2 * 1 = 120 (5! means 5 factorial)

4! = 4 * 3 * 2 * 1 = 24 (4! means 4 factorial)

#### FACTORIAL USING RECURSION IN JAVA

Also Read – Factorial Program in Java

```import java.io.BufferedReader;
import java.io.IOException;

public class FactorialUsingRecursion {

public static void main(String[] args) throws NumberFormatException, IOException{

System.out.println("Please enter number to calculate its factorial:");

int x = Integer.parseInt(br.readLine());

// Here we call the recursive function to generate factorial
int result = factorial(x);

System.out.println("Factorial of " + x + " is = " + result);
}

static int factorial(int y)
{
if(y <= 1)
return 1;
else
return y * factorial(y - 1);
}
}```

Output:

Sharing is healthy !!