Factorial of a number (Recursive Function)
To learn more about how to make a program in java watch this video https://youtu.be/TRm9r4gFTho
The factorial of a number is the product of all the integers from 1 to that number.
Recursion :- The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function. To learn more about recursion click the given link.
Recursion
To learn more about how to make a program in java watch this video https://youtu.be/TRm9r4gFTho
Write a recursive program to print the factorial of a number.
import java.io.*;
public class FactorialRecur
{
int num;
void input()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the number");
num=Integer.parseInt(br.readLine());
}
int factorial(int n)
{
if(n==0)
return 1;
else
return(n*factorial(n-1));
}
void display()
{
System.out.println("the factorial of the number is:"+factorial(num));
}
public static void main()throws IOException
{
FactorialRecur obj=new FactorialRecur();
obj.input();
obj.display();
}
}Output:
Enter the number
4
The factorial of the number is : 24
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.