Search Tutorials


Tuesday, 23 April 2013

Java code to calculate factorial of a number using recursion

Java program to calculate factorial of a number using recursion.

class Factorial
 public static void main(String args[]) throws IOException
 BufferedReader br = new BufferedReader(new InputStreamReader(;
 Factorial call = new Factorial();
 System.out.print("Enter a number : ");
 int n = Integer.parseInt(br.readLine());
 System.out.println("Factorial = " +call.fact(n));
 int fact(int n)
  return 1;
  return n*fact(n-1);


1. Start

2. Accept a number n from the user.

3. Using method of recursion, multiply all the numbers upto n.

4. Print the Factorial.

5. End


Java code to print factorial of a number using recursion

Enter a number : 5
Factorial = 120

Related Programs:-

Generate Fibonacci series using recursion

Find the HCF & LCM of two numbers using recursion

Find the sum of the following series using recursion : 12 + 22 + 32 +.......+ n2

Find the sum of Natural numbers up to a given number using Recursion

Calculate the Power of a number using recursion

No comments:

Post a Comment

back to top