文档库 最新最全的文档下载
当前位置:文档库 › 翁凯-JAVA

翁凯-JAVA

1.写一个简单的应声虫程序,读入用户输入的文字,在输出的时候在前面加上“ECHO:”这个字符串。比如,

输入:

hello

输出

ECHO: hello

包括20题单项选择题和10题填空题

1

单选(3分)

对于以下代码:

1.for( int i=0; i<10; i++)

2.System.out.println(i);

for循环后,i的值是多少?

? A.9

? B.11

? C.i不再存在了

? D.10

2

单选(3分)

以下哪个for语句是错误的?

? A.for (;;);

? B.for ( i=0; j<10; j++ );

? C.for (i=0; i<10; i--);

? D.for (i=0,j=0; i<10; i++; j++ );

3

单选(3分)

对于以下代码段:

1.String s1 = "a";

2.String s2 = "b";

3.String s3 = "";

以下操作可以编译的是:

? A.

1.s3 = s1 && s2;

?

? B.

1.s3 = s1 + s2;

?

? C.

1.s3 = s1 - s2;

?

? D.

1.s3 = s1 & s2;

?

4

单选(3分)

以下代码片段之行后,temp的值是?

1.int temp = (int)3.9;

2.temp %= 2;

? A.0

? B.3

? C.1

? D.2

5

单选(3分)

表达式

…B?+…8?-…3?

表示的字符是:

? A.69

? B.G

? C.g

? D.5

6

单选(3分)

对于

int x, y;

语句

1.if(x < 0)

2.y = -1;

3.else if(!x)

4.y = 0;

5.else

6.y = 1;

等价于

? A.

1.y=0;

2.if(x!=0)

3.if(x>0)

4.y=1;

5.else

6.y=-1;

?

? B.

1.if(x != 0)

2.if(x > 0)

3.y = 1;

4.else

5.y = -1;

?

? C.

1.y=0;

2.if(x>=0)

3.if(x)

4.y=1;

5.else

6.y=-1;

?

? D.

1.if(x>=0)

2.y=0;

3.if(x)

4.y=1;

5.else

6.y=-1;

?

7

单选(3分)

以下哪个是有效的Java程序入口函数?

? A.public static void main();

? B.public static int main(int argc, *char[] argv);? C.public static void main(int argc, *char[] argv);? D.public static void main(String[] args);

8

单选(3分)

以下代码片段:

1.String s1 = "hello";

2.String s2 = "hello";

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

以下哪句是正确的?

? A.输出“false”

? B.运行时刻出现异常

? C.输出“true”

? D.不能编译

9

单选(3分)

有以下定义:

double a,b,c;

则以下哪个表达式与a/b/c不等价?

? A.(a/b)/c

? B.a/c/b

? C. A. a/(b/c)

? D.a/(b*c)

10

单选(3分)

以下哪个循环并非重复5次?

? A.int i; for (i=1; i<=5; i++) {}

? B.int i; for (i=0; i<=5; i++) {}

? C.int i; for (i=0; i<5; i++) {}

? D.int i; for (i=1; i<6; i++) {}

11

单选(3分)

以下哪个不是Java语言的关键字?

? A.if

? B.class

? C.System

? D.do

12

单选(3分)

以下哪段代码可以编译:

? A.

1.int i;

2.for( i=5, int j=10; j<10; j-- ) ;

?

? B.

1.int i,j;

2.for( i=0; j=10; i<10; i++, j--);

?

? C.

1.int i,k;

2.for( i=0, k=9; i<10&& k>0; i++, k--);

?

? D.

1.int i,j;

2.for( i=0, j=10; i<10, j>0; i++, j--);

?

13

单选(3分)

以下哪个函数是不能编译的?

? A.

1.void f()

2.{

3.}

?

? B.

1.int f(void)

2.{

3.return0;

4.}

?

? C.

1.int f()

2.{

3.return0;

4.}

?

? D.

1.void f(int i)

2.{

3.return i;

4.}

?

14

单选(3分)

以下代码片段编译运行的结果是:

1.int Output=10;

2.boolean b1 = false;

3.if((b1==true) && ((Output+=10)==20)){

4.System.out.println("We are equal "+Output);

5.} else{

6.System.out.println("Not equal! "+Output);

7.}

? A.输出"Not equal! 10"

? B.输出"Not equal! 20"

? C.编译错误

? D.输出"We are equal 10"

15

单选(3分)

有以下代码片段:

int m[] = {0, 1, 2, 3, 4, 5, 6 };

以下哪项可以给出数组的单元个数?

? A.m.length()+1

? B.m.length()

? C.m.length

? D.m.length+1

16

单选(3分)

对于String s;,以下哪句是对的?

? A.s是一个变量,它将要管理一个String的对象? B.s是一个变量,其中有一个String的对象? C.s是一个变量,它管理着一个String的对象? D.s现在的值是null

17

单选(3分)

以下哪句不能编译?

? A.if ( a==b ) {} else System.out.println("no");? B.if ( a==b ) System.out.println("no");

? C.if ( a==b ); else System.out.println("no");? D.if ( a==b ) else System.out.println("no"); 18

单选(3分)

以下哪个循环能编译?

? A.for ( i=10 ,i<100, i++ ) {}

? B.for ( i=10 ; i<100 ) {}

? C.for ( i=10 ; i++ ) {}

? D.for ( i=10 ; i++; ) {}

19

单选(3分)

对于以下代码:

int i,j=6;

以下哪句话是对的?

? A.i被初始为0,而j是6

? B.i和j的初始值都是6

? C.i不会被初始化,而j是6

? D.不能通过编译

20

单选(3分)

对于以下代码:

1.int i=6;

2.if( i<= 6)

3.System.out.println("hello\n");;

4.else

5.System.out.println("bye-bye\n");;哪句话是对的?

? A.打印出"bye-bye"

? B.打印出"hello bye-bye"

? C.通不过编译

? D.打印出"hello"

21

填空(3分)

以下程序片段:

1.Loop1:

2.while( true) { // 1

3.for( ; true; ) {

4.if( i ==2)

5.break Loop1; // 2

6.}

7.i=4; // 3

8.}

9.i=5; // 4

当语句2执行后,程序跳转到注释所标注的哪句去执行?4

22

填空(3分)

表达式

(double)(10/4*4)

的结果是:

8.0

23

填空(3分)

以下代码片段的输出是:

1.int i=1;

2.switch(i) {

3.default:System.out.print("default");

4.case0: System.out.print("zero");break;

5.case1: System.out.print("one");

6.case2: System.out.print("two");break;

7.}

one

24

填空(3分)

字符'A'的Unicode编码为65,那么以下代码片段的输出是:System.out.println('A'+6+2);

73

25

填空(3分)

表达式

(double)(10/4)

的值为

2.0

26

填空(3分)

以下代码段的输出是:

1.int number, right_digit;

2.number = 15292;

3.if( number ==0) {

4.System.out.println("0");

5.} else

6.while( number != 0) {

7.right_digit = number % 10;

8.System.out.println(right_digit);

9.number /= 10;

10.}

29251

27

填空(3分)

表达式-17%4的结果是

-1

28

填空(3分)

以下代码片段的结果是:

1.int i = 3;

2.int j = 0;

3.double k = 3.2;

4.if( i

5.if( i==j )

6.System.out.println(i);

7.else

8.System.out.println(j);

9.else

10.System.out.println(k);

29

填空(3分)

以下代码片段的输出是:

System.out.println(""+6+12);

612

30

填空(3分)

以下代码片段执行后,s的值是?

1.String s = "hello";

2.s = s+" world ";

3.s.toUpperCase();

4.s=s.trim();

hello world

相关文档
相关文档 最新文档