更多“ 下列程序的输出结果是( )。A.Catch---1B.Catch---2C.Catch---3D.以上都不对 ”相关问题
  • 第1题:

    下列程序的输出结果是( )。

    A.编译未通过

    B.编译通过,但运行错误

    C.可以运行,但有错误

    D.以上都不对


    正确答案:B
    这是-道考查数组引用的题,目的是考查如何在程序中引用初始化后的数组。引用的方式为arrayName[index],其中index为数组的下标,可以为整数、变量和表达式,范围从0开始,-直到数组的长度减l。在Java语言中,是要对数组下标进行检查的。因此。当程序运行到数组的长度值时,就发生了越界现象。

  • 第2题:

    下列程序的输出结果是( )。 Public class Test{ Public static void main(String[]args){ int[]array=(2,4,6,8,10); int size=6; int result=-l: try{ for(int i=0;i<sizeresult= =-1:) if(array[i]= =20)result=i: } catch(ArithmeticException e){ System.out.println("Catch---1"); } catch(ArraylndexOutOfBoundsException e){ System.out.println("Catch---2"): } catch(Exception e){ System.out.println("Catch---3"): } }

    A.Catch---1

    B.Catch---2

    C.Catch---3

    D.以上都不对


    正确答案:B
    B。【解析】本题考查了数组及for循环。本题数组定义的值为5,下标从0~4。数组越界,所以答案为B。

  • 第3题:

    以下程序的输出结果是: nums=[1,2,3,4] nums.append([5,6,7,8]) print(len(nums)

    A.4

    B.5

    C.8

    D.以上都不对


    B

  • 第4题:

    阅读下面程序 public class Cycle { public static void main(String[] args) { System.out.println(args[0]); } } 在命令行输入java Cycle one two,该程序输出的结果是

    A.Cycle

    B.one

    C.two

    D.以上三个选项都不对


    正确答案:B
    解析:在main()方法中参数表中定义的数组args用于接收命令行参数。在题中提到命令行java Cycle one two中参数分别为“one”、“two”,它们将被依次存放在数组args中。由于在Java中数组的下标从0开始,所以输出字符串args[0]为“one”。

  • 第5题:

    下列程序的输出结果是( )。 public class Test{ public static void main(String[]args){ int[]array=(2,4,6,8,lO); int size=6; int result =-1: try{ for(int i=0;i(size 8L&result= = -1;) if(array[i]= =20)result=i: } catch(ArithmeticException e){ System.out.println("Catch- - -l"); } catch(ArraylndexOutOfBoundsException e){ System.out.println("Catch- - -2"); } catch(Exception e){ System.out.println("Catch- - -3");) } }

    A.Catch- - -1

    B.Catch- - -2

    C.Catch- - -3

    D.以上都不对


    正确答案:B
    B。【解析】由题可知先判断i<sizeresuh==-1,结果为真,则执行if语句array数组中的任何数都不等于20,并且i从0开始一直到i=5时发生越界,则输出Cateh==-2,结果为B。