We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1c3a0e2 commit fdf1017Copy full SHA for fdf1017
CodingBlocks Training/Recursion/sumOfNTerms.java
@@ -0,0 +1,18 @@
1
+package Recursion;
2
+
3
+public class sumOfNTerms {
4
5
+ public static void main(String[] args) {
6
7
+ int n = 10;
8
+ System.out.println(nthSum(n)); // 55
9
+ System.out.println(nthSum(3)); // 6
10
+ }
11
12
+ public static int nthSum(int n) {
13
+ if (n == 0) {
14
+ return 0;
15
16
+ return n + nthSum(n - 1);
17
18
+}
0 commit comments