Skip to content

Commit 90930aa

Browse files
add: Recursion Demo
1 parent 8e598ed commit 90930aa

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

04-methods/.idea/uiDesigner.xml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class RecursionDemo {
2+
public static void main(String[] args) {
3+
int val = 5;
4+
int result = factorial(val);
5+
System.out.println("Factorial of " + val + " is " + result);
6+
}
7+
8+
// Define the method
9+
static int factorial(int num) {
10+
// Base case: 0! = 1
11+
if (num == 0) {
12+
return 1;
13+
} else {
14+
// Recursive case: num! = num * (num - 1)!
15+
return num * factorial(num - 1);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)