当前页面: 开发资料首页 → J2SE 专题 → 程序抛出错误问题!
程序抛出错误问题!
摘要: 程序抛出错误问题!
各位帮忙看下,这个程序输出时怎么会提示这个错误:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at newpackage.CopyArrayWhile.main(CopyArrayWhile.java:18)
class CopyArrayWhile{
public static void main(String[] arguments) {
int[] array1 = {2,3,1,2,4,1,2};
float[] array2 = new float[array1.length];
System.out.print("array1: [ ");
for (int i = 0; i
System.out.print(array1[i] + " ");
}
System.out.println("]");
System.out.print("array2: [");
int count1 =0;
for(int count=0;count<=array1.length;count++){
if(array1[count]==1){
continue;
}else{
array2[count1]=(float)array1[count];
System.out.print(array2[count1]+" ");
count1++;
}
}
System.out.println("]");
}
}
将:for(int count=0;count<=array1.length;count++){
改为:
for(int count=0;count
数组溢出了
public class CopyArrayWhile ??
数组是从0开始走的,LENGH测的是实际长度
完全同意楼上几位的说法!答案就是将:
for(int count=0;count<=array1.length;count++){
改为:
for(int count=0;count
如上,接分
谢谢各位的解答,现在就给分!