I'm trying to solve a homework problem for an algorithms class and I keep getting an out of bounds index array for the code I've written below. I've been trying to play around with it in Python since I'm pretty comfortable with that, but I seem to be getting a similar exception. Can anyone give me a hint as to where I'm going wrong with this?
public class Fibonacci1 {
public static long F(int N) {
long a[] = new long [100];
a[0] = 0; /*sets up first 2 digits in the sequence*/
a[1] = 1;
if (N<2) {
return N;
}
a[N] = a[N-1] + a[N-2]; /*appends F num for next number in the list*/
N++;
return a[N]; /*should return the last number*/
}
public static void main(String[] args) {
for (int N = 0; N<100; N++)
StdOut.println(N+" " + F(N));
}
}