import java.util.HashMap; import java.util.Map; public class Fibonacci { private static final Map computed = new HashMap(); static { Fibonacci.computed.put(1, 1L); // base case Fibonacci.computed.put(2, 1L); // base case } public static long value(int n) { long value; if(Fibonacci.computed.containsKey(n)) { value = Fibonacci.computed.get(n); } else // recursive case { value = value(n - 1) + value(n - 2); } Fibonacci.computed.put(n, value); return value; } }