结构推理 编写Java程序,包含三种异常:算术异常、字符串越界、数组越界,并对每个异常对象可以直接给出信息。
【正确答案】参考程序
   public class first_exception
   {
   public static void main (String args[])
   {
    char c;
    int  a,b=0;
    int[]  array=new int[7];
       String  s="Hello";
    try
    {
     a=1/b;
    }
   catch(ArithmeticException ae)
   {
     System.out.println("Catch "+ae)) ;
     }
     try
     {
     array[8]=0;
     }
   catch (ArrayIndexOutOfBoundsException ai)
   {
   System.out.println(("Catch "+ai) ;
   }
   try
   {
    c=s.charAt(8)) ;
    }
   catch (StringIndexOutOfBoundsException se)
   {
   System.out.println(("Catch "+se) ;
     }
    }
   }
【答案解析】