Oct 12, 2020

What is Recursion with Example?

Calling a function within itself again and again finite/infinite times is called recursion. It is complex but makes the code compact.

Example: Write a program to find the factorial of a number using recursion?

public class Recursion{
static int factorial(int num){
If (num==1)
return 1;
return (n*factorial(n-1));
public static void main(String[] args){
System.out.println("Factorial of 5 is:"+factorial(5));

No comments:

Post a Comment

Thanks a lot for your valuable Comment!

Featured this week

Latest Employment BUZZ: 4 working days in a week?

COVID-19 has hit mostly all sectors including IT  too bad. If we think otherwise, on the other hand,  there have been many new technical inn...