Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyFibonacci {
- public static final int MAX = 100;
- public static long[] buildArray(int MAX, int N) {
- long[] A = new long[MAX];
- A[0] = 0;
- A[1] = 1;
- for(N = 2; N < MAX; N++)
- A[N] = F(N);
- return A;
- }
- public static long F(int N) {
- if(N == 0)
- return 0;
- if(N == 1)
- return 1;
- return F(N - 1) + F(N - 2);
- }
- public static void main(String[] args) {
- for(int N = 0; N < MAX; N++)
- System.out.println(N + " " + A[N]);
- }
- }
- long[] A = buildArray(MAX, 0);
- static int MAX = 100;
- static long[] A;
- public static void buildArray()
- {
- A = new long[MAX+1];
- F(MAX);
- }
- public static long F(int N)
- {
- long val;
- if (N < 2)
- val = N;
- else if (A[N] != 0) // HEY! It's already calculated! Awesome! Just return it.
- return A[N];
- else
- val = F(N-1) + F(N-2);
- A[N] = val;
- return val;
- }
- public static void main(String[] args)
- {
- buildArray();
- for (int N = 0; N <= MAX; N++)
- System.out.println(N + " " + A[N]);
- }
- public class MyFibonacci{
- public static final int MAX = 100;
- long[] A = new long[MAX];
- public static long[] buildArray(int N){
- A[0] = 0;
- A[1] = 1;
- for (N = 2; N < MAX; N++){
- A[N] = F(N);
- }
- return A;
- }
- public static long F(int N)
- {
- if (N == 0) return 0;
- if (N == 1) return 1;
- return F(N-1) + F(N-2);
- }
- public static void main(String[] args)
- {
- buildArray(<some number - not sure where you get it from? N by the way in buildArray()>);
- for (int N = 0; N < MAX; N++)
- StdOut.println(N + " " + A[N]);
- }
- }
- public static long[] f_a(int n) {
- long[] a = new long[n];
- a[1] = 1;
- for (int i = 2; i < n; i++)
- a[i] = a[i-1] + a[i-2];
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement