try {  int x = 0;  int y = 5 / x;  } catch (Exception e) { 

题目
单选题
try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()
A

 finished

B

 Exception

C

 Compilation fails.

D

 Arithmetic Exception

参考答案和解析
正确答案: A
解析: The correct answer to this question is D. When an int value is divided by zero, a runtime exception occurs. There are no compilation errors. 
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列函数原型声明中错误的是

A.void Fun(int x=O,int y=0);

B.void Fun(int x,int y);

C.void Fun(int x,int y=0);

D.void Fun(int x=0,int y);


正确答案:D
解析:本题考核函数的定义方法和调用方法。说明一个函数的格式为:函数类型>函数名>,(下函数参数表>);在C++中,允许在函数的说明或定义时给一个或多个参数指定默认值。但一旦为某个给定参数定义了缺省值,必须为后继的所有参数也定义缺省值。由此可知,选项D是错误的。

第2题:

给定C语言程序:

int foo(int x, int y,int d)

{

if ( x !=0 ) {

if ( y == 0 ) d = d / x;

else d=d/(x*y);

} else {

if ( y == 0 ) d = 0;

else d=d/y;

}

return d;

}

当用路径覆盖法进行测试时,至少需要设计(31)个测试用例。

A.3

B.4

C.5

D.8


正确答案:B
解析:路径覆盖法是白盒测试的作用方法,要求设计足够多的测试用例,覆荒程序中所有可能的路径。给定程序的流程图如下图所示。
  从图中可以看出,程序中共存在四条路径,分别记为abdh、abeh、acfh、acgh。当用路径覆盖法设计测试案例时,必须为每条路径至少设计一个用例。下面给出一组可覆盖全部路径的测试用例。
  测试用例1:[(2,0,8),4],覆盖路径abdh
  测试用例2:[(2,2,8),2],覆盖路径abeh
  测试用例3:[(0,0,8),0],覆盖路径acfh
  测试用例4:[(0,2,8),4],覆盖路径acgh
  用例采用形式[输入的(x,y,d),返回的d]来描述。

第3题:

阅读下面程序: include void fun(int n) { int x(5); static int y(10); if(n>0) {

阅读下面程序:

include<iostream.h>

void fun(int n)

{

int x(5);

static int y(10);

if(n>0)

{

++x;

++y;

cout<<x<<","<<y<<end1;

}

}

void main()

{

int m(1);

fun(m);

}

则该程序的输出结果是______。


正确答案:611
6,11

第4题:

下面程序的运行结果为_____。 include void fun(int x=0,int y=0) { cout < < x < <

下面程序的运行结果为_____。

include<iostream.h>

void fun(int x=0,int y=0)

{

cout < < x < < y;

}

void main( )

{

fun(5) ;

}


正确答案:50
50 解析:本题考查的是函数的默认参数,如果一个函数中有多个参数,则默认参数应从右至左逐个定义,所以题目中x使用参数5,y使用默认参数0。

第5题:

有如下程序:include void fun (int& x,int y){int t=x;x=y;y=t;}int main(){ int

有如下程序: #include <iostream> void fun (int& x,int y){int t=x;x=y;y=t;} int main() { int a[2]={23,42}; fun (a[1],a[0]; std::cout<<a[0]<<”,”<<a[1]<<std:: ond1; retum0; }执行后的输出结果是______ 。

A.41,41

B.23,23

C.13,42

D.42,23


正确答案:B
解析:a[0]做的是地址传递,所以执行函数后值发生变化,而a[1]做的是值传递,值并没有发生变化,所以此题应选择A。

第6题:

执行以下程序段后,变量x=______,y______。

int x=5;

int y=0;

y = --x * 3;


正确答案:4 12
4 12

第7题:

下列代码的执行结果是______。

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+23/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

D) 2

error2 error2

A.

B.

C.

D.


正确答案:C

第8题:

阅读下面程序: include void f(int n) { int x(5); static int y(10); if(n>0) { ++

阅读下面程序:

include<iostream.h>

void f(int n)

{

int x(5);

static int y(10);

if(n>0)

{

++x;

++y;

cout<<x<<","<<y<<endl;

}

}

void main()

{

int m(1);

f(m),

}

则该程序的输出结果是【 】


正确答案:611
6,11

第9题:

以下程序执行后的输出结果是( )。include usingnamespacestd;void try(int,int,int,in

以下程序执行后的输出结果是( )。 #include <iostream> using namespace std; void try(int,int,int,int); int main ( ) { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = X*X; y = y*y; r = z+x+y; }

A.18

B.9

C.10

D.不确定


正确答案:D
解析:本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。下面是正确解答。根据程序逐步分析:①程序中定义了一个名为try的void型函数,即函数try()没有任何返回值。②而try()函数在主函数中是以一条独立语句的方式被调用的,且主函数最后输出变量r的值。③但在主函数中,并没有对变量r赋值。④在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以,虽然在函数try()中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

第10题:

有如下程序:include void fun(int& x, int y){int t=x;x=y;y=t;}int main (){int

有如下程序: #include <iostream> void fun(int& x, int y){int t=x;x=y;y=t;} int main () { int a[2]={23,42}; fun(a[1],a[0]); std::cout<<a[0]<<","<<a[1]<<std::endl; return 0; } 执行后的输出结果是

A.42,42

B.23,23

C.23,42

D.42,23


正确答案:B
解析:本题考核函数的调用以及参数值的传递。函数fun中的第一个参数采用引用传值方式,函数中对形参值的改变同样作用于实参上;第二个参数采用按值传值方式,函数中对形参的操作不会影响到实参。所以main函数中调用fun函数后,a[1]的值被修改为a[0]的值,而a[0]的值没有改变。

更多相关问题