We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f15c427 commit 94d8731Copy full SHA for 94d8731
1 file changed
algorithms/FibonacciRecursiveEx.java
@@ -0,0 +1,27 @@
1
+package com.zetcode;
2
+
3
+import java.math.BigInteger;
4
5
+public class FibonacciRecursiveEx {
6
7
+ private static final BigInteger[] fibCache = new BigInteger[100000];
8
9
+ static {
10
+ fibCache[0] = BigInteger.ONE;
11
+ fibCache[1] = BigInteger.ONE;
12
+ }
13
14
+ public static BigInteger fibonacci(int b) {
15
16
+ if (fibCache[b] == null) {
17
+ fibCache[b] = fibonacci(b - 1).add(fibonacci(b - 2));
18
19
20
+ return fibCache[b];
21
22
23
+ public static void main(String[] args) {
24
25
+ System.out.println(fibonacci(99));
26
27
+}
0 commit comments