We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 23dd9c6 + adbf34c commit 280509fCopy full SHA for 280509f
1 file changed
Miscellaneous/NthFibonacci.java
@@ -0,0 +1,21 @@
1
+class NthFibonacci {
2
+
3
+ /*
4
+ * Print the nth Fibonacci number for a given number, n
5
+ * using recursion
6
+ */
7
8
+ static int fib(int n) {
9
+ if (n <= 1) {
10
+ return n;
11
+ }
12
+ return fib(n - 1) + fib(n - 2);
13
14
15
+ public static void main(String[ ] args) {
16
17
+ int n = 5;
18
+ System.out.println(fib(n));
19
20
21
+}
0 commit comments