What is Recursion with Example? - Software Testing

Empowering Technology

Post Top Ad

Responsive Ads Here

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!

Post Bottom Ad

Responsive Ads Here