这段程序哪里出了错,为啥编译失败?
- class Demo
- {
- int div(int a,int b)
- {
- int[]arr = new int[a];
- System.out.println(arr[4]);
- return a/b;
- }
- }
- class ExceptionDemo2
- {
- public static void main(String[] args)
- {
- Demo d = new Demo();
- try
- {
- int x = d.div(5,0);
- System.out.println("x="+x);
- }
- catch (Exception e)
- {
- System.out.println("haha:"+e.toString());
- }
- catch(ArithmeticException e )
- {
- System.out.println(e.toString());
- System.out.println("被零除啦");
- }
- catch(ArrayIndexOutOfBoundsException e)
- {
- System.out.println(e.toString());
- System.out.println("角标越界啦!!!");
- }
- System.out.println("Over");
- }
- }
复制代码
|