forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacciRecursiveEx.java
More file actions
27 lines (18 loc) · 552 Bytes
/
FibonacciRecursiveEx.java
File metadata and controls
27 lines (18 loc) · 552 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.zetcode;
import java.math.BigInteger;
public class FibonacciRecursiveEx {
private static final BigInteger[] fibCache = new BigInteger[100000];
static {
fibCache[0] = BigInteger.ONE;
fibCache[1] = BigInteger.ONE;
}
public static BigInteger fibonacci(int b) {
if (fibCache[b] == null) {
fibCache[b] = fibonacci(b - 1).add(fibonacci(b - 2));
}
return fibCache[b];
}
public static void main(String[] args) {
System.out.println(fibonacci(99));
}
}