Created
March 25, 2013 14:44
-
-
Save wfwei/5237595 to your computer and use it in GitHub Desktop.
Fib...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mine.old.staff; | |
| public class Fib { | |
| static final int MAX = 93; | |
| static long[] f = new long[MAX]; | |
| static { | |
| f[0] = 0; | |
| f[2] = f[1] = 1; | |
| } | |
| public static long fib(int n) { | |
| if (n < 3) | |
| return f[n]; | |
| for (int i = 3; i <= n; i++) | |
| f[i] = f[i - 1] + f[i - 2]; | |
| return f[n]; | |
| } | |
| public static void main(String args[]) { | |
| for (int i = 1; i < MAX; i++) { | |
| System.out.println(fib(i)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment