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

题目

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

public class Test{

public static void main(String[] args){

int [] array={2,4,6,8,10};

int size=6;

int result=-1;

try{

for{int i=0;i<size && result==-1;i++}

if(array[i]==20) result=i;

}

catch(ArithmeticException e){

System.out.println( " Catch---1 " );

catch(ArrayIndexOutOfBoundsException e){

System.out.println( " Catch---2 " );

catch(Exception e){

System.out.println( " Catch---3 " );

}

}

A ) Catch---1

B ) Catch---2

C ) Catch---3

D )以上都不对


相似考题
更多“( 17 )下列程序的输出结果是public class Test{public static void main(String[] args){int [] ”相关问题
  • 第1题:

    下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { for ( int a=0;a<10;a++) { if (a==5) break; System.out.println(A); } } }

    A.01234

    B.6789

    C.012346789

    D.5


    正确答案:A
    解析:题目中输出语句位于循环体内,而在if语句外,所以a5时执行输出语句。当a=5时,退出循环,结束程序的执行。

  • 第2题:

    下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te

    A.0

    B.1

    C.2

    D.3


    正确答案:C

  • 第3题:

    下列程序的输出结果是_______。

    class Test{

    public static void main(String args []){

    int m=6;

    do{m--:}while(m>0);

    System.out.println("m="+m);

    }

    }


    正确答案:×
    0

  • 第4题:

    下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { int n=10; do { System.out.println("n is"+n); }while(--n>10); } }

    A.n is 8

    B.没有输出

    C.n is 10

    D.n is 9


    正确答案:C
    解析:do-while循环至少执行一次,输出n is 10。判断结束条件时,先计算--n,n=9,才进行比较运算,所以条件为假,退出循环。因此选C。

  • 第5题:

    下列程序的输出结果是class Test{public static void main(String args[]){int n=7;n<<=3;n=n&am

    下列程序的输出结果是 class Test{ public static void main(String args[]){ int n=7; n<<=3; n=n&n+1|n+2^n+3; n>>=2; System.out.println(n); } }

    A.0

    B.-1

    C.14

    D.64


    正确答案:C
    解析:本题考查Java中的运算符。首先要清楚程序里面涉及的运算符的含义。“”是按位左移运算符,“&”是按位与运算符,“|”是按位或运算符,“^”是按位异或运算符。题目中整型变量n=7相当于二进制中的111,n=3语句执行后,n值为111000,相当于十进制的56,而语句n=n&n+1|n+2^n+3执行后,n值为57;n>>=2语句执行后,n的值为14,所以选项C正确。

  • 第6题:

    以下程序运行后输出的结果是______。

    public class exl7

    {

    public static void main(String args [])

    {

    int a = 0;

    for(int j = 1; j <= 20; j++)

    if(j%5 != 0)

    a = a + j;

    System.out.println (a);


    正确答案:160
    160

  • 第7题:

    下列程序运行的结果是( )。public class Test { public static void main(String[] args) { int a=2,b=3; System.out.println( (a>b?" *** a =" :" ###b = ") + A) ; } }

    A.*** a=2

    B.*** a=3

    C.### b=2

    D.### b=3


    正确答案:C
    解析:本题输出的结果是条件表达式(a>b?" *** a =":" ###b =")的值和a连接之后的结果,由于a,b不成立,因此条件表达式的结果为“###b =”,再和a连接后输出为“###b =2”。

  • 第8题:

    下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }

    A.hello

    B.HELLO

    C.hemmo

    D.HEMMO


    正确答案:A
    解析:String类的replace (char oldChar,char newChar)函数的作用是返回一个新的字符串,它是通过用newChar替换此字符串中出现的所有oldChar而生成的。返回的是新字符串,但是原字符串变量的值并未发生改变。因此,输出的是“hello”而不是“hemmo”。如果替换语句换为: s=s.replace('l','m');,则输出“hemmo”。

  • 第9题:

    下列程序的输出结果是( )。 public class Test { void printValue(int m) { do{ System.out.println("The value is"+m) } while(--m>10) } public static void main(String args[]) { int i=10; Test t=new Test: t.printValue(i); } }

    A. The value is 8

    B.The value is 9

    C.The value is 10

    D.The value is 11


    正确答案:C
    C。【解析】此题考查的是do-while循环和“--”操作符的知识。do-while最少执行一次,在执行完d0中的内容后,判断while中的条件是否为true。如果为true,就再执行do中的内容,然后进行判断。以此类推,直到while的判断为false时退出循环,执行循环后面的内容。而“--”操作符的规则是,变量右边的“-”将先进行运算,然后才使变量的值减一。而在变量左边的“--”,则先将变量的值减1再运算。本程序中i的值为10,当程序运行到do-while循环时,程序先执行一次循环,然后判断,因此选C。

  • 第10题:

    以下程序的输出结果为:public class test {public static void main(String args[]) {int m=0;for ( int k=0;k<2;k++)method(m++);System.out.println(m);}public static void method(int m) {System.out.print(m);}}

    A. 000

    B. 012

    C.123

    D.111


    正确答案:B

  • 第11题:

    以下是JAVA中正确的入口方法是? () 

    • A、 public static void main(String[] args){}
    • B、 public static void main(String args){}
    • C、 public void main(String[] args){}
    • D、 public static int main(String[] args){}

    正确答案:A

  • 第12题:

    作为Java应用程序入口的main方法,其声明格式可以是()。

    • A、public static void main(String[] args)
    • B、public static int main(String[] args)
    • C、public void main(String[] args)
    • D、public int main(String[] args)

    正确答案:A

  • 第13题:

    以下Java应用程序执行入口main方法的声明中,正确的是( )。

    A.public static void main()

    B.public static void main(String[] args)

    C.public static int main(String[] args)

    D.public void main(String[] args)


    参考答案:B

  • 第14题:

    下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic int i=0; i++; System.out.println(i); } public static void.main(String args[]) { Test test=new Test(); test.aMethod(); }

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出


    正确答案:A

  • 第15题:

    下列代码的执行结果是public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } public static void main(String args[]){ Test test= new Test(); test. aMethod(); }}

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出


    正确答案:A
    解析:static不能修饰局部变量。

  • 第16题:

    下列程序的输出结果是 interface Inter{ public final static int A=100; } class My implements Inter{ public static void main (String args[ ]) {System.out.println(A) ; }

    A.100

    B.0

    C.A

    D.程序有错误


    正确答案:A
    解析:本题主要考查接口的定义和使用,接口是一种含有抽象方法和常量的一种特殊的抽象类,不能包含成员变量,在程序中是输出常量A的值,所以输出的结果为5。

  • 第17题:

    下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { int j=2,i=5; while (j<i--) j++; System.out.println(j);} }

    A.2

    B.3

    C.4

    D.5


    正确答案:C
    解析:循环时,首先判断结束条件,25,然后i=4,j=3,继续循环,i=3,j=4,结果条件ji为假,退出循环,因此j=4。所以选C。

  • 第18题:

    下列程序的执行结果是( )。 public class Test { public static void main(String args[]) { System.out.println(5/2); } }

    A.2.5

    B.2

    C.2.5

    D.2


    正确答案:D
    解析:如果表达式中有不同的数据类型,则寻找自动转换是优先级最高的一个,其他数值全部转换成这种数据类型,当然表达式的值也是这种数据类型。有可能会选择选项A,请注意数据类型之间的关系,结果的数据类型必须和表达式中优先级最高的一个一样。在这里,表达式和结果都是int型。

  • 第19题:

    下列代码的执行结果是( )。

    public class Test{

    public int aMethod( ){

    static int i=0;

    i++;

    System.out.println(i):

    }

    public static void main (String args[]){

    Trest test=new Test ( );

    test aMethod( ):

    }

    }

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出

    B.

    C.

    D.


    正确答案:A

  • 第20题:

    阅读下面的程序public class Test {public static void main(String[] args) {for(int x = 0 ; x <=3 ; x++){continue;System.out.print(x%2);}}}运行结果正确的是

    A.跳出循环,无输出

    B.0121

    C.01

    D.0123


    答案:A
    解析:continue语句的作用是终止本次循环,因此contine后的代码永远不会被执行,都是无效代码

  • 第21题:

    下列程序的输出结果是 class Test{public static void main(Siring args[]){int n=7;n<<=3;n=n&a

    下列程序的输出结果是 class Test{ public static void main(Siring args[]){ int n=7; n<<=3; n=n&n+1/n+2^n+3; n>>=2; System.out.printtn(n); -} }

    A.0

    B.1

    C.14

    D.64


    正确答案:C
    解析:本题考查Java中的运算符。首先要清楚程序里面涉及的运算符的含义。“”是按位左移运算符,“&”是按位与运算符,“|”是按位或运算符,“^”是按位异或运算符。题目中整型变量n=7相当于二进制中的111,n=3语句执行后,n值为111000,相当于十进制的56,而语句n=n&n+1|n+2^n+3执行后,n值为57,n>>=2语句执行后,n的值为14,所以选项C正确。

  • 第22题:

    以下程序调试结果为:

    public class Test {

    int m=5;

    public void some(int x) {

    m=x;

    }

    public static void main(String args []) {

    new Demo().some(7);

    }

    }

    class Demo extends Test {

    int m=8;

    public void some(int x) {

    super.some(x);

    System.out.println(m);

    }

    }

    A.5

    B.8

    C.7

    D.无任何输出

    E.编译错误


    正确答案:B

  • 第23题:

    Which declarations will allow a class to be started as a standalone program?()  

    • A、public void main(String args[])
    • B、public void static main(String args[])
    • C、public static main(String[] argv)
    • D、final public static void main(String [] array)
    • E、public static void main(String args[])

    正确答案:D,E

  • 第24题:

    单选题
    以下是JAVA中正确的入口方法是? ()
    A

     public static void main(String[] args){}

    B

     public static void main(String args){}

    C

     public void main(String[] args){}

    D

     public static int main(String[] args){}


    正确答案: D
    解析: 暂无解析