Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fibonacci 2
import java.util.*; import java.lang.*; /*Taken from http://introcs.cs.princeton.edu/java/23recursion/TopDownFibonacci.java.html 20170504*/ class Rextester { private static long[] f = new long[92]; public static long fibonacci(int n) { if (n == 0) return 0; if (n == 1) return 1; // return cached value (if previously computed) if (f[n] > 0) return f[n]; // compute and cache value f[n] = fibonacci(n-1) + fibonacci(n-2); return f[n]; } public static void main(String[] args) { int n = 10; for (int i = 0; i <= n; i++) System.out.print(" i" + i + ": " + fibonacci(i)); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Job and Trait Generator
palin
ArrayOperation
linear search
2darray
Partition Palindrome (BackTracking) #131
java274
luas
Sort an array of 0's 1's 2's 3 pointer approach
binary
Please log in to post a comment.