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

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.