public class Arrays {
public static void main(String[] args){
long Fib[] = new long[100];
Fib[0] = 1;
Fib[1] = 1;
int i = 0;
while(i <= 100){
Fib[i+2]= Fib[i] + Fib[i+1];
System.out.println(Fib[i]);
i++;
}
}
}
我用它来找到斐波那契数,但它在第 94 学期左右开始给我奇怪的读数。有人愿意解释吗?我对Java完全陌生,所以如果它很明显,请不要讨厌。这是错误输出的一些片段,但其他一切看起来都很好:
832040
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100
1346269
...
63245986
at Arrays.main(102334155
Arrays.java:8)
165580141
...
4660046610375530309
7540113804746346429
-6246583658587674878
1293530146158671551
-4953053512429003327
-3659523366270331776
-8612576878699335103
6174643828739884737