给代码做异常处理
public class seven2{ public static void main(String[] args){ int score[]; score=new int[3]; try{ //会出现异常的代码块用try括起来 for(int x=0;x<4;x++) //定义的数组长度为三,循环却跑到了四,属于数组越界 score[x]=x*2+1; for(int x=0;x<3;x++) System.out.println("score["+x+"]="+score[x]); } catch(ArrayIndexOutOfBoundsException e){ //抛出数组越界异常 System.out.println("数组越界异常:"+e); } } }