任何人都可以幫助我擺脫這種異常?異常在線程「主」java.lang.ArrayIndexOutOfBoundsException:200
public class Obs2 {
int [] ary=new int[200];
int c=1,b,d,x,y,s,j,p,v=0;
int i=1;
public int find(int N){
for(int a=2;a<100;a++)
{
s=a;
do
{
x=a/2;
y=a%2;
if(y==0)
{
a=x;
}
}while(y==0 && x!=1);
if(y==0 && x==1)
{
ary[v]=s; //This is line 28
++v;
}
else if(y!=0 && a>2)
{
do{
j=a/3;
c=a%3;
a=j;
}while(c==0 && j!=1);
if(c==0 && j==1)
{
ary[v]=s;
v++;
}
}
}
return ary[N];
}
public static void main(String[] args)
{
Obs2 obs =new Obs2();
System.out.print(obs.find(10)); //And this is line 56
}
}
我的輸出說
異常線程 「main」 java.lang.ArrayIndexOutOfBoundsException:200
在obs2.Obs2.find(Obs2.java:28)
在obs2.Obs2.main(Obs2.java:56)
如何避免使用變量名'l'發瘋? !它看起來像一個'1'。大聲笑。 – gonzo
你有什麼試圖擺脫例外?代碼中的第28行和第56行在哪裏? (你可能想添加//註釋)。 –
更改變量名稱我的眼睛在流血。 – dguay