Java基础学习(六)基本语法5之数组常见异常

1.数组下标越界的异常:java.lang.ArrayIndexOutOfBoundsException

int[] i = new int[10];

// i[0] = 90;

// i[10] = 99;

// for(int m = 0;m <= i.length;m++){

// System.out.println(i[m]);

// }

 

2.空指针的异常:NullPointerException

//第一种:

// boolean[] b = new boolean[3];

// b = null;

// System.out.println(b[0]);

 

//第二种:

// String[] str = new String[4];

// //str[3] = new String("AA");//str[3] = "AA";

// System.out.println(str[3].toString());

//第三种:

int[][] j = new int[3][];

j[2][0] = 12;

weinxin
我的微信
有问题微信找我
DannyWu

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

Protected with IP Blacklist CloudIP Blacklist Cloud