猿问

编译器没有显示错误,但不知道为什么运行失败

package practice;


public class practice6{

private static int dayNumber;

private int way;

private static double sum;

private static int[] number1={2,3,4,2,3,1};

private static int[] number2={2,5,4,1,0,1};

public void jisuan(int way){

switch(way){

case 1:new practice6().jisuan1();break;

case 2:new practice6().jisuan2();break;

}

}

public static void jisuan1(){

int dixin=dayNumber*40;

int tichen=0;

for(int a=0;a<=number1.length;a++){

tichen=5*number1[a];

}

sum=dixin+tichen;

}

public static void jisuan2(){

int dixin=dayNumber*50;

double tichen=0;

for(int a=0;a<=number1.length;a++){

tichen=3*number1[a];

}

sum=dixin+tichen;

}

public static void main(String[] args) {

practice6 p6=new practice6();

p6.jisuan(2);


}

}


枫夜流萤
浏览 1616回答 2
2回答

精慕门9254224

肯定是ArrayIndexOutOfBoundsException ,数组下标越界异常

望远

for(int a=0;a<=number1.length;a++){ tichen=5*number1[a]; }for(int a=0;a<=number1.length;a++){ tichen=3*number1[a]; }数组下标越界for(int a=0;a<number1.length;a++){ }下标是从0--length-1的length个元素下标
随时随地看视频慕课网APP

相关分类

Java
我要回答