就业数据资源平台
当前位置:首页 > Java语言程序设计
2011年计算机等级考试二级Java笔试练习题(3)

 1 阅读下列代码段:

  Int i=3, j ;


  Outer : while (i>0)


  {


  J=3 ;


  Inner:while (j>0)


  {


  If (j<2) break inner;


  System.out.println(j+”and”+i) ;


  j-- ;


  }


  i -- ;


  }


  下列哪一项将不会被输出到屏幕上?


  A ) 3and3 B) 3and2 C) 3and1 D)3and0


  2. 如果要抛出异常,应该采用的子句是----------


  A) catch B) throw C) try D) finally


  3.阅读下面代码段:


  Public class person


  {


  Int arr [ ]= new int [10];


  Public static vond main (string a[ ])


  {


  System.out.println(arr[1]);


  }


  }


  执行结果正确的说法是------------。


  A) 编译时将产生错误 B) 编译时正确,运行时将产生错误


  C) 输出零 D) 输出空


  4.阅读下面代码段:


  Public class Test


  {


  Public static void main (string args [ ])


  {


  Char ch ;


  Switch (ch)


  {


  Case ‘a’: system.out.print(“abc”);break;


  Case’b’: system.out.print(“ab”);


  Case’c’: system.out.print(“c”);break;


  Default: system.out.print(“abc”);


  }


  }


  }


  不输出”abc”的ch值是-----------。


  A)’a’ B) ‘b’ C) ‘c’ D) ‘d’


  5.和语句


  For (int x=0;x <15; x+=2) sum+=x+5;


  作用一样的语句是--------------。


  A) for (int x =5; x<20;x+=2)sum+=x;


  B) for(int x=5;x<20;x+=x-2)x+=2;


  C) for(int x=0;x<15;x+=2)sum+=x+3;x+=2;


  D) 上述全对  


  6. 阅读下列代码:


  Public class Test{


  Public static void mian ( String args[] ) {


  Float a=4.0f, b=6.0f, c=8.0f;


  String s=”10.0”;


  System.out.println(a+b+s+c);


  System.out.println();


  }


  }


  程序运行结果为________.


  A) absc B) 4.06.0101.08.0


  C) 10.010.08.0 D) 4.06.010.08.0


  7. 阅读下列代码:


  Public class Test{


  Public static void main ( String args[] ) {


  String s1= new String(“hello”);


  Stirng s2= new String(“hello”);


  Stirng s3= s1;


  System.out.println( s1 = =s2 );


  System.out.pirntln( s1 = = s3 );


  }


  }


  程序运行结果为_________.


  A) true,false B) true,true C) false,true D) false,false


8. 下面运算符中优先级最高的是_________.

  A) >> B) * C) && D) +=


  9. 阅读下列代码:


  Public class Test{


  Public static void main ( String args[] ) {


  int a = 10,b = 6;


  Syetem.out.println(a & b );


  }


  }


  程序运行结果为_________.


  A) 2 B) 6 C) 10 D) 16


  10 和语句


  y=x+7;


  x++;


  While (x<9)


  {


  y=x+7;


  x++;


  }


  执行结果相同的语句是------------


  A) y=x+7;


  x++;


  do{


  y=x+7;


  x++;


  }while (x<9)


  B) do {


  y=x+7;


  x++;


  }while (x<9)


  C) do {


  y=x+7;


  x++;


  }while (x<=9)


  D) 上述都不对


  11下列可以实现无限循环的语句是-------------


  A) for (;;) {…} B) if(true){…}


  C) while(false) {…} D) 上述都可以


  12请写出下列代码段的输出结果:


  Int x=12,y=14,z;


  z=y/x+7;


  x=z*z;


  system.out.println(x);


  13阅读下列代码段:


  Int x=10,y=12,r;


  If (y>x)


  {


  int t=y;


  Y=x;


  X=t;


  }


  While (y!=0)


  {


  R=x%y;


  X=y;


  Y=r;


  }


  System.out.println(x);


  程序运行结果为----------


  A)2 B)4 C) 6 D)8


 14. 阅读下面程序:

  Pulbic class Test extends TT


  {


  Public static void main ( String args[] )


  {


  Test t = new Test ( “ Tom” )


  }


  Public Tests ( String s )


  {


  super(s);


  System.out.println(“How do you do ?”);


  }


  Public Test()


  {


  this ( “ I am Jack” );


  }


  }


  class TT


  {


  public TT()


  {


  System.out.println(“What a pleasure!”);


  }


  public TT( Stirng s )


  {


  this();


  System.out.println(“I am”+s);


  }


  }


  给出程序结果.


  15 用if-else 语句改写下面的switch语句:


  Switch (i) {


  Case 1:


  J+=2;


  Break;


  Case3:


  J-=5;


  Break;


  Case7:


  Case10:


  J*=17;


  Break;


  Default:


  J=0;


  }


  答案


  1.D 2.B 3.A 4.C 5.D 6.C 7.C 8.B 9.A10.B 11.A 12.64 13.A


  14. What a pleasure!


  I am Tom


  How do you do?


  15.IF (i= =1)j+=2;


  Else if (i= =3)j-=5;


  Else if (i= =7||i= =10)j*=17;


  Else j=0;

就业数据资源平台