Recursive Functions
Recursive Functions
Java allows us to recursively call a method many times, which helps us solve different type of problems.
Example:
Output:
Java allows us to recursively call a method many times, which helps us solve different type of problems.
Example:
public class RecursiveMethod {
static int fact(int num) {
if (num != 0)
return num * fact(num-1);
else
return 1;
}
public static void main(String[] args) {
int num1 = 6, res;
res = fact(num1);
System.out.println("Factorial of " + num1 + " is " + res);
}
}
Output:
Factorial of 6 is 720
Sorry, we detected that you have activated Ad-Blocker.
Please consider supporting us by disabling your Ad-Blocker, it helps us in developing this Website.
Thank you!