finished
Exception
Compilation fails.
Arithmetic Exception
第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
第2题:
有如下程序: #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
第3题:
下面程序的运行结果为_____。
include<iostream.h>
void fun(int x=0,int y=0)
{
cout < < x < < y;
}
void main( )
{
fun(5) ;
}
第4题:
for(int x=0,y=0;!x&&y<=5;y++)语句执行循环的次数是( )。
A.0
B.5
C.6
D.无穷
第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);
第6题:
以下程序执行后的输出结果是 #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.不确定
第7题:
在下面程序运行后,输出结果为 ______。 #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
第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();
}
第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?()
第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?()
第11题:
protected int blipvert(long x) { return 0; }
protected long blipvert(int x) { return 0; }
private int blipvert(long x) { return 0; }
private int blipvert(int x) { return 0; }
public int blipvert(int x) { return 0; }
protected long blipvert(long x) { return 0; }
protected long blipvert(int x, int y) { return 0; }
第12题:
finished
Exception
Compilation fails.
Arithmetic Exception
第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.
第14题:
以下程序执行后的输出结果是( )。 #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.不确定
第15题:
有如下程序: #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
第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
第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)
第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)
第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
第20题:
以下程序执行后的输出结果是 #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.不确定
第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 ?()
第22题:
Which two code fragments are most likely to cause a StackOverflowError?()
第23题:
Thread.sleep(1);
Thread.sleep(100);
Thread.sleep(1000);
try{ Thread.sleep(1); ) catch (Exception e) { }
try{Thread.sleep(100); ) catch (Exception e) { }
try{Thread.sleep(1000); ) catch (Exception e) { }
第24题:
int []x = {1,2,3,4,5};for(int y = 0; y < 6; y++) System.out.println(x[y]);
static int[] x = {7,6,5,4};static { x[1] = 8;x[4] = 3; }
for(int y = 10; y < 10; y++)doStuff(y);
void doOne(int x) { doTwo(x); }void doTwo(int y) { doThree(y); }void doThree(int z) { doTwo(z); }
for(int x = 0; x < 1000000000; x++) doStuff(x);
void counter(int i) { counter(++i); }