class Demo1
{
public static void main(String[] args)
{
//数组的两种写法
int[] x = new int[2];
int[] y = new int[]{12,23};
//如果使用第一种的话,就要给他们赋值
x[0] = 12;
x[1] = 42;
System.out.println(x[1]+"+"+y[1]);
}
}
ArrayIndexOutOfBoundsException 操作数组是,访问到了数组中不存在的角标,角标越界异常
NullPointerException 空指针异常
class Demo2
{
public static void main(String[] args)
{
int[] x = new int[3];
System.out.println(x[3]);//显示ArrayIndexOutOfBoundsException 3
x = null;
System.out.println(x[1]);//显示NullPointerException
}
}