查找字符串,编译通过了,可是运行不行,大家帮着找找哪里需要改动
public class FindString{
public static void main(String[] args)
{
String string1="I don't wanna say goodbye to you";
int len=string1.length();
int j=17;
int i=9;
int k=0;
char []a=new char[len];
a[0]=string1.charAt(i);
for( ; i<=j ; i++){
for(;;k++){
a[k]=string1.charAt(i);
}
}
String string2=new String(a);
System.out.println("the char at "+i+" is:"+a[0]);//字符查找
System.out.println("the string from"+i+"to"+j+"is:");//串查找
System.out.println(string2);
}
}
--------------------Configuration: <Default>--------------------
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32
at FindString.main(FindString.java:17)
Process completed.