数组中的常见异常
作者:互联网
数组角标越界的异常 ArrayIndexOutOfBoundExcetion
数组角标越界异常
int [] arr = new int[]{1,2,3,4,5};
for(int i = 0;i < = arr.length){
System.out.println(arr[i]);
}
System.out.println(arr[-2]);
原理:共有五个数,后面输出指令让系统寻找第六位数,故出现指针异常
空指针异常 NullPointterException(常见)
//情况1
int[] arr1 = new int[]{1,2,3};
arr1 = null;
System.out.println(arr1[0]);
for(int i = 0;i<yanghui.length;i++){
yanghui[i] = new int[i+1];
//给首末元素赋值
yanghuiu[i][0]=yanghui[i][i];
//给每行的非首末元素赋值
for(int = j;j<yanghui[i].length-1;j++){
yanghui[i][j] = yanghui[i-1][j-1] +yanghui[i-1][j];}
}
标签:arr,int,常见,System,数组,yanghui,new,异常,out 来源: https://blog.csdn.net/WalnutP/article/details/113822838