/ 知识库     / 试卷库

单项选择题(2011年3月二级考试)

下列代码的执行结果是 【 】

public class Test {
    public static void main(String[] args){
        int[] x={0,1,2,3};
        for(int i=0;i<3;i+=2){
            try{
                System.out.println(x[i+2]/x[i]+x[i+1]);
            }catch(ArithmeticException e){
                System.out.println("error1");
            }catch(Exception e){
                System.out.println("error2");
            }
        }
    }
}

A、error1

B、error2

C、

error1

error2

D、

2

error2

答案解析

关键词

error;system;out;线程;public;int;catch;java;程序;线程的调度;

下列程序的运行结果是 【 】public class test{     private String[] data={“10”,“10.5”};     public void fun(){         double s=0;         for(int i=0;i<3;i++){             try{                 s=s+Integer.parseInt(data[i]);             }catch(Exception e){                 System.out.print(“errorl:”+data[i]);             }         }     }     public static void main(String[] args){         try{             testd=new test();             d.fun();         }catch(Exception e){             System.out.printIn(“error2”);         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }

下列代码的执行结果是 【 】public class Test {     public static void main(String[] args){         int[] x={0,1,2,3};         for(int i=0;i<3;i+=2){             try{                 System.out.println(x[i+2]/x[i]+x[i+1]);             }catch(ArithmeticException e){                 System.out.println("error1");             }catch(Exception e){                 System.out.println("error2");             }         }     } }