SUN_Java程序员认证考试题库(三)

 

    1.现有:

    class TestApp{

    public static  void main (String[]  args){

    for (int i=0; i<lO;i++){

    if(i==3)

    break;

    System. out .print (i);

    }

    }

    }

    程序运行后的输出是哪项?

    A.0123

    B.012456789

    C. 0123456789

    D.  012

   

2.程序:

    class  TestApp{

    public static  void main (String[]  args){

    int x=6;

    if (x>l)

    System. out. println("x>l");

    else if (x>5)

    System. out .println("x>5");

    else if (x<10)

    System. out. println("x<lO");

    else if (x<29)

    System. out .println( "x<29");

    else

    System. out.println(“以上都不是”);

    }

    }

    上述程序运行后的结果是哪项?

    A.x>5

    B.x>l

    C.  x<10

    D.x<29


    3.现有:

    class TestApp{

    public static  void main (String[]  args){

    int [5]  myarray={ 10, 11, 12, 13, 14);

    int sum=0;

    for (int x :  myarray)

    sum+=x;

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

    }

    }

    上述程序运行后的结果是哪项?

    A. sum=10

    B. sum=70

    C. sum=60

    D. 运行时抛出异常

   

4.下列有关数组的声明中,正确的是哪项?(选两项)

    A. int s[10];

    B. int[10] s;

    C. int[5] s={l,2,3,4,5};

    D. int s[];

   

5.已知数组array,其最后一个元素的下标是?

    A. array. size

    B. array. length-l

    C. array. size-l

    D. array.length

   

6.程序:

    class   TestApp{

    public static void main (String[]  args){

    int X=5:

    switch (x){

    case l:

    case 2:

    case 3:

    System. out.println(“一季度”);

    break;

    case4:

    case 5:


    case 6:

    System. out.println(“二季度”);

    break;

    default:

    System. out.println(“三季度以上”);

    break;

    )

    }

    )

    上述程序运行后的结果是哪项?

    A. 一季度

    B.二季度

    c.三季度以上

    D.无输出

   

7.为将数组myArray的长度由3改为6,现采取以下编码:

    int[]myArray=new int [3];

    myArray=new int[6];

    代码执行后,以下叙述哪项是正确的?

    A.数组myArray的长度已由3改为6,其中前3个元素的值不变,后3个元素

    的值为空。

    B.数组myArray的长度已由3改为6,其中前3个元素的值不变,后3个元素

    需再经过初始化后才能使用。

    C.数组myArray的长度没有变化。

    D.数组myArray的长度已由3改为6,原来3个元素的值全部丢失。

   

8.现有:

    1. class  Ifs  {

    2.public static void main (String  []  args) {

    3.boolean state=false;

    4.    inti=2;

    5.if( (++i>2) &&  (state=true))

    6.i++;

    7.if( (++i>4) l l  (state=false))

    8.i++;

    9.System.out .println (i);

    10.   }

    11.  }


   

    结果为:

    A.  6

    B.  5

    C.  4

    D.编译失败

   

9.现有:

    3.  publicclass Tester {

    4.public static void main (String[]args)  {

    5.   intx-5;

    6.   Integer xl=x;  Integer x2=x;

    7.int x3=new Integer(5);

    8.   system..ut.print(x1.equals(x));

    9.   system..ut.print(xl==x);

    lu.   system..ut.print(x2.equals(xl));

    11.   system..ut.print(x2==xl);

    12-   system..ut.print(x2==x3);

    13-   system..ut.print(x2.equals(x3));

    “    l4.}

    15.  }

    结果为:

    A.编译失败

    B. falsefalsetruetruetruetrue

    C. truetruetruetruetruetrue

    D. falsefalsetruetruetruefalse

    E. truefalsetruefalsefalsetrue

    F.运行时异常被抛出

   

10.现有:

    1.  classRectangle  {

    2'   public static V.id main(string []  args)    {

    3.   int[]x=(1,2,3);

    4.   x[1]=  (x[1]>1) ?x[2]:  O;

    5.   System.out.println(x[1]);

    6.    }

    7.    }


    结果为:

    A.3

    B.2

    C.1

    D.0

   

11.现有:

    1.class Output (

    2.public static void main (String[]  args)   {

    3.    inti=5:

    4.System.out.print("4"+i+"");

    5.System.out.print (i+5+"7");

    6.System.out.println  (i+"8");

    7.    }

    8.  }

    结果为:

    A.  9 9722

    B.  9 55758

    C.  4510758

    D.  459722

   

12.以下哪种初始化数组的方式是错误的?

    A. String[]names={"zhang",   "wang",   "li");

    B. String names[]  =new  String [3];

    names [O] ="zhang";  names[1]  ="wang";   names [2] ="li";

    C. String[3] names={"zhang","wang", "li"};

    D. 以上皆正确

   

13.现有:

    1.  classWhileTests  {

    2.public static void main (String  []  args) {

    3.    intX=5;

    4.    while(++x<4)  {

    5.--x;

    6.    }

    7.System.out.println( "x="+x);

    8.    }

    9.  }


    结果是什么?

    A.X=6

    B. X=5

    C.X=2

    D.编译失败

   

14.现有:

    1.  class Test2  f

    2.public static void main (String  [] args)  {

    3.   boolean X= true;

    4.   boolean y=false;

    5.    shortZ=20;

    6.

    7.if((x==true) &&  (y=true)) z++;

    8.   if((y==true) ||  (++z==22))  z++;

    9.

    10.    System.out .println( "z="+z);

    11.    }

    12.  }

    结果是什么?

    A.Z=21

    B. z=22

    C. z=23

    D.  Z= 24

   

15.现有:

    1.  classFoo  {

    2.public static void main (String  [] args)  {

    3.    intx=O;

    4.    inty=4;

    5.for (int z=0;  z<3; Z++;  X++)  {

    6.   if(x>1&++y<10)

    7.    y++;

    8.    }

    9.System. out .println (y);

    10.    }

    11.  }

    结果是什么?

    A.7

    B.8

    C.10

    D.12


                            I D

                            2B

                            3C

                            4CD

                            5B

                            6B

                            7D

                            8A

                            9C

                            11 C

                            12 C

                            13 A

                            14 B

    15B

                           

猜你喜欢

转载自blog.csdn.net/u013767488/article/details/52780665