单选题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?()AfinishedBExceptionC

题目
单选题
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


相似考题
更多“try {  int x = 0;  int y = 5 / x;  } catch (Exception e) { ”相关问题
  • 第1题:

    给定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]来描述。

  • 第2题:

    有如下程序: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。

  • 第3题:

    下面程序的运行结果为_____。 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。

  • 第4题:

    for(int x=0,y=0;!x&&y<=5;y++)语句执行循环的次数是( )。A.0B.5C.6SXB

    for(int x=0,y=0;!x&&y<=5;y++)语句执行循环的次数是( )。

    A.0

    B.5

    C.6

    D.无穷


    正确答案:C
    此题是典型的考题。题中x=0,则!x永远为真,对于条件表达式!x&&y<=5只考虑y<=5,由于每次循环y都增加1,而且y从0开始到5。所以可知总共循环了6次。

  • 第5题:

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

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

    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++中函数的声明,如果第一个参数有默认值,那么第二个参数也应该有默认值,否则出错。

  • 第6题:

    以下程序执行后的输出结果是include using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #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<<endl; 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函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在c++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第7题:

    在下面程序运行后,输出结果为 ______。includevoid count(int x[],int n,int &y

    在下面程序运行后,输出结果为 ______。 #include<iostream.h> void count(int x[],int n,int &y){ int k; y=0; for(k=0:k<n;k++) if(x[k]<0) y++; } void main(){ int b[]={2,1,-8,-3,7,2,4,6,0,-13}; int x; count(b,10,x); cout<<“x”<<x<<end1; }

    A.x=3

    B.x=5

    C.出错

    D.x=0


    正确答案:A

  • 第8题:

    include<iostream.h>

    class A

    {

    private:

    int x,y;

    public:

    void f1(int i=0,int j=0){x=i;y=j;}

    void print(){cout<<x<<" "<<y<<endl;}

    void f1(int i=0){x=i,y=0;}

    };

    void main()

    {

    A a;

    a.f1(5);

    a.print();

    }


    正确答案:
    a.f1(5);重载函数产生了二义性。应删去其中一个函数f1。

  • 第9题:

    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

    正确答案:D

  • 第10题:

    1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()  

    • A、 public int blipvert(int x) { return 0; }
    • B、 private int blipvert(int x) { return 0; }
    • C、 private int blipvert(long x) { return 0; }
    • D、 protected long blipvert(int x, int y) { return 0; }
    • E、 protected int blipvert(long x) { return 0; }
    • F、 protected long blipvert(long x) { return 0; }
    • G、protected long blipvert(int x) { return 0; }

    正确答案:A,C,D,E,F

  • 第11题:

    多选题
    Given: Which five methods, inserted independently at line 5, will compile?()
    A

    protected int blipvert(long x) { return 0; }

    B

    protected long blipvert(int x) { return 0; }

    C

    private int blipvert(long x) { return 0; }

    D

    private int blipvert(int x) { return 0; }

    E

    public int blipvert(int x) { return 0; }

    F

    protected long blipvert(long x) { return 0; }

    G

    protected long blipvert(int x, int y) { return 0; }


    正确答案: C,F
    解析: 暂无解析

  • 第12题:

    单选题
    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. 

  • 第13题:

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

    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

  • 第14题:

    以下程序执行后的输出结果是( )。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,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第15题:

    有如下程序: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]的值没有改变。

  • 第16题:

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

    A.errorl

    B.error2

    C.errorl orror2

    D.2 error2


    正确答案:C
    C。【解析】当0作为除数时,会产生异常,而ArithmeticException和Exception两类异常都内部被捕捉到。

  • 第17题:

    阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

    【函数2.1】

    void sort(char *s,int num)

    {int i,j--num;

    char t;

    while(j-->1)

    for(i=0;i<j;i++)

    if(s[i]>s[i+1])

    {t=s[i];

    s[i]=s[i+1];

    s[i+1]=t;

    }

    void main()

    {char *s="CEAedea";

    sort(s,5);

    printf("%s",s);

    }

    上述程序的结果是(1)

    【函数2.2】

    void main()

    { union {int ig[6];

    Char s[12];} try;

    try. ig[0]=0x4542; try.ig[1]=0x2049;

    try. ig[2]=0x494a; try.ig[3]=0x474e;

    try. ig[4]=0x0a21; try.ig[5]=0x0000;

    pintf("%s",try, s);

    }

    上述程序的结果是(2)

    【函数2.3】

    void main()

    { char *letter[5]= { "ab","efgh","ijk","nmop","st"};

    char **p;

    int i;

    p=letter;

    for(i=0;i<4;i++) .

    printf("%s",p[i]);

    }

    上述程序的结果是(3)

    【函数2.4】

    main()

    {int i=4,j=6,k=8,*p=&I,*q=&j,*r=&k;

    int x,y,z;

    x=p==&i;

    y=3*-*p/(*q)+7;

    z=*(r=&k)=*p**q;

    printf("x=%d,y=%d,z=%d",x,y,z);

    }

    上述程序的结果是(4)

    【函数2.5】

    int a[]={5,4,3,2,1 };

    void main()

    {int i;

    int f=a[0];

    int x=2;

    for(i=0;i<5;i++)

    f+=f*x+a[i];

    printf("%d",f);

    }

    上述程序的结果是(5)


    正确答案:(1)ACEdeea (2) BEI JING! (3) abefghijkmnop (4) x=1y=5z=24 (5) 129
    (1)ACEdeea (2) BEI JING! (3) abefghijkmnop (4) x=1,y=5,z=24 (5) 129

  • 第18题:

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

    A.void fuc(int x=0,int y=0)

    B.void fnc(int x,int y)

    C.void fuc(int x,int y=0)

    D.void fuc(int x=0,int y)


    正确答案:D
    解析:C++允许在函数的说明或定义中给一个或多个参数指定默认值。但默认值必须从右向左定义,即在一个指定默认值的参数的右边,不能出现没有指定默认值的参数。

  • 第19题:

    以下( )表达式是不合法的。

    A.String x="Sky";int y=5;x + =y:

    B.String x="Sky":int y=5:if(x==y){}

    C.String x="Sky":int y=5:x=x+y:

    D.String x=null:int y=(x!=null) && (x.length( )>0)?x.length:0


    正确答案:B

  • 第20题:

    以下程序执行后的输出结果是include.using namespace std;void try(int,int,int,int)

    以下程序执行后的输出结果是 #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函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第21题:

    5. class Order2 implements Runnable {  6. public void run() {  7. for(int x = 0; x 〈 4; x++) {  8. try { Thread.sleep(100); } catch (Exception e) { }  9. System.out.print("r");  10. } }  11. public static void main(String [] args) {  12. Thread t = new Thread(new Order2());  13. t.start();  14. for(int x = 0; x 〈 4; x++) {  15. // insert code here  16. System.out.print("m");  17. } } }  哪一个插入到第15行,最有可能产生输出 rmrmrmrm ?()  

    • A、Thread.sleep(1);
    • B、Thread.sleep(100);
    • C、Thread.sleep(1000);
    • D、try { Thread.sleep(100); } catch (Exception e) { }

    正确答案:D

  • 第22题:

    Which two code fragments are most likely to cause a StackOverflowError?()

    • A、int []x = {1,2,3,4,5};for(int y = 0; y < 6; y++)    System.out.println(x[y]);
    • B、static int[] x = {7,6,5,4};static { x[1] = 8;x[4] = 3; }
    • C、for(int y = 10; y < 10; y++)doStuff(y);
    • D、void doOne(int x) { doTwo(x); }void doTwo(int y) { doThree(y); }void doThree(int z) { doTwo(z); }
    • E、for(int x = 0; x < 1000000000; x++) doStuff(x);
    • F、void counter(int i) { counter(++i); }

    正确答案:D,F

  • 第23题:

    单选题
    现有:  5.  class Order2 implements Runnable  {     6.    public void run()  {     7. for (int x- o;  x<4;  x++)  {  8. try{Thread.sleep(100);  )catch  (Exception e)  {  }     9.    System.out.print("r");     10.    }  }  11.    public static void main(string  []  args)  {     12.    Thread t=new Thread(new order2());     13.    t.start();  14.    for(int x=0;  x<4;  x++)  {     15.    //insert code here     16.    System.out.print("m");     17.  }  }  }  哪一个插入到第15行,最有可能产生输出 rmrmrmrm?()
    A

      Thread.sleep(1);

    B

      Thread.sleep(100);

    C

      Thread.sleep(1000);

    D

      try{  Thread.sleep(1);  )  catch  (Exception e)  {  }

    E

      try{Thread.sleep(100);  )  catch  (Exception  e)  {  }

    F

      try{Thread.sleep(1000);  )  catch  (Exception  e)  { }


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

  • 第24题:

    多选题
    Which two code fragments are most likely to cause a StackOverflowError?()
    A

    int []x = {1,2,3,4,5};for(int y = 0; y < 6; y++)    System.out.println(x[y]);

    B

    static int[] x = {7,6,5,4};static { x[1] = 8;x[4] = 3; }

    C

    for(int y = 10; y < 10; y++)doStuff(y);

    D

    void doOne(int x) { doTwo(x); }void doTwo(int y) { doThree(y); }void doThree(int z) { doTwo(z); }

    E

    for(int x = 0; x < 1000000000; x++) doStuff(x);

    F

    void counter(int i) { counter(++i); }


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