Topic: javac Zy19.java可以通过,为什么java Zy19就报错呢? |
Print this page |
1.javac Zy19.java可以通过,为什么java Zy19就报错呢? | Copy to clipboard |
Posted by: 义仔小馒头 Posted on: 2006-11-21 21:39
C:\jdk\1>java Zy19 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at Zy19.main(Zy19.java:7) |
2.Re:javac Zy19.java可以通过,为什么java Zy19.java就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: lovon1921 Posted on: 2006-11-21 23:27 循环语句里面i=0的时候,下面就变成了f[0]=f[-1]+f[-2]了...i=1的时候也一样. |
3.Re:javac Zy19.java可以通过,为什么java Zy19.java就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: 义仔小馒头 Posted on: 2006-11-22 20:50 我也想到了,但是不知道该如何解决?请赐教! |
4.Re:javac Zy19.java可以通过,为什么java Zy19.java就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: gmazp Posted on: 2006-11-26 13:33 "javac Zy19.java可以通过,为什么java Zy19'.java'就报错呢?" java Zy19.java ?你没有搞错吧!把".java"去了看看! |
5.Re:javac Zy19.java可以通过,为什么java Zy19.java就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: 义仔小馒头 Posted on: 2006-11-27 17:40 我说错了,是java Zy19报错呀! |
6.Re:javac Zy19.java可以通过,为什么java Zy19.java就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: why Posted on: 2006-11-27 18:04 义仔小馒头 wrote: ArrayIndexOutOfBoundsException for (int i=2 ... |
7.Re:javac Zy19.java可以通过,为什么java Zy19.java就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: sunxiaoming Posted on: 2006-11-27 23:53 public static void main(String[] args){ int [] f=new int[20]; f[0]=1;f[1]=2; for(int i=0;i<20;i++){ // int i = 2 f[i]=f[i-1]+f[i-2]; System.out.println(f[i]);} } int i =0 时 f[i]=f[i-1]+f[i-2]; 是什么? 错误在这里 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException 已经告诉你是数组 的问题了 |
8.Re:javac Zy19.java可以通过,为什么java Zy19就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: lisliefor Posted on: 2006-11-28 11:00 循环出了问题,地一次进入循环,如果i的初始值为0,那么接下来的表达式为: f[0] = f[-1] + f[-2]; 这里数组越界了。正如WHY所说,仔细想想。 |
9.Re:javac Zy19.java可以通过,为什么java Zy19就报错呢? [Re: 义仔小馒头] | Copy to clipboard |
Posted by: 义仔小馒头 Posted on: 2006-11-28 22:09 谢谢楼上的些前辈指点! 小弟已经明白了! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |