Skip to content

Commit 94d8731

Browse files
authored
Create FibonacciRecursiveEx.java
1 parent f15c427 commit 94d8731

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)