Skip to content

Commit af7c8ac

Browse files
committed
prints numbers from 1 to N given N, using recursion
1 parent e5d1015 commit af7c8ac

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package CodingNinja.recursion;
2+
3+
public class printNumbers1toN {
4+
5+
public static void printNum(int n) {
6+
if (n == 0) // base case
7+
return;
8+
9+
printNum(n - 1); // recursive call
10+
11+
System.out.println(n);
12+
}
13+
14+
public static void main(String[] args) {
15+
printNum(5);
16+
}
17+
}

0 commit comments

Comments
 (0)