There was an error while loading. Please reload this page.
2 parents b6caad2 + 9dd7203 commit 7bec626Copy full SHA for 7bec626
Mathematics/fibonacci/FibonacciRecursive.java
@@ -0,0 +1,19 @@
1
+public class FibonacciRecursive {
2
+ public static void main (String[]args) {
3
+ System.out.println (nfib (0)); // Output - 0
4
+ System.out.println (nfib (1)); // Output - 1
5
+ System.out.println (nfib (2)); // Output - 1
6
+ System.out.println (nfib (3)); // Output - 2
7
+ System.out.println (nfib (4)); // Output - 3
8
+ System.out.println (nfib (5)); // Output - 5
9
+ }
10
+
11
+ static int nfib (int n) {
12
13
+ if (n == 0) return 0;
14
15
+ if (n == 1) return 1;
16
17
+ return nfib(n - 1) + nfib(n - 2);
18
19
+}
0 commit comments