( 17 )下列程序的输出结果是public class Test{public static void main(String[] args){int []

题目

( 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 )以上都不对

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列程序的运行结果是【 】。

public class Test {

public static void main (String args[]) {

String s1="hello!";

System.out.println (s1.toUpperCase());

}}


正确答案:HELLO!
HELLO! 解析:在String类的常用方法中,toUpperCaee()方法将当前字符串中的所有小写字母转化成大写,其他字符保持不变。

第2题:

下面程序段的输出结果是( )。 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时,退出循环,结束程序的执行。

第3题:

若有如下程序:

public class Test {

public static void main (String[] args) {

int x=20;

if (x>10) System.out.print(x-=5);

if (x>5) System.out.print(x--);

}

}则程序运行后的输出结果是【 】。


正确答案:1515
1515 解析:本题中第一次if语句条件判断时,x的值为20,x>10成立,所以执行其后的输出语句,输出的值x-=5为一个复合赋值运算符组成的表达式,相当于x=x-5,所以x被赋以15,表达式x-=5的值也是15;执行第二次if语句判断时,x的值为15,x>5成立,所以执行其后的输出语句,输出表达式x-的值,由于自减运算符--在变量x之后,所以是先取变量x的值作为表达式的值,然后变量x再作自减运算,所以表达式x--的值为15。所以两次输出的结果在屏幕上显示为:1515。

第4题:

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

class Test{

public static void main(String args []){

int m=6;

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

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

}

}


正确答案:×
0

第5题:

下面程序的输出结果是什么? 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

第6题:

如下程序的输出结果是( )。 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
解析:此题考查的是do-while循环和“--”操作符的知识。do-while最少执行一次,在执行完do中的内容后,判断while中的条件是否为true。如果为true,就再执行do中的内容,然后再进行判断。以此类推,直到while的判断为false时退出循环,执行循环后面的内容。而“--”操作符的规则是,变量右边的“--”将先进行运算,然后才使变量的值减一。而在变量左边的“--”,则先将变量的值减一再运算。本程序中I的值为10,当程序运行到do-while循环时,程序先执行一次循环后然后再做判断,因此选C。

第7题:

以下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

第8题:

下列程序段的输出结果是【 】。

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);

}

}


正确答案:Thevalue is 10
Thevalue is 10 解析:本题考查do-while循环的用法。do-while至少执行一次,在执行完do中的内容后,判断while中的条件是否为true。如果为true,就再执行do中的内容,然后再进行判断。依次类推,直到while的判断为false时退出循环,执行循环后面的内容。题目中m的值为10,当程序运行到do-while循环时,程序先执行一次循环然后再作判断,在判断条件--m>10时,其值为false,退出循环。因此只执行了一次输出操作,输出内容为:The value is 10。

第9题:

下列程序的执行结果是 ( ) 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

第10题:

下列代码的执行结果是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不能修饰局部变量。

更多相关问题