java题库(3)

1970-01-01 08:00

boolean even = (number % 2 == 0); A)Code 1 has compile errors.

B)Both Code 1 and Code 2 are correct, but Code 2 is better. C)Both Code 1 and Code 2 have compile errors. D)Code 2 has compile errors.

13)Suppose income is 4001, what is the output of the following code: if (income > 3000) {

System.out.println(\}

else if (income > 4000) {

System.out.println(\A)no output

B)Income is greater than 3000

C)Income is greater than 4000 followed by Income is greater than 3000 D)Income is greater than 3000 followed by Income is greater than 4000 E)Income is greater than 4000

14)The ________ method immediately terminates the program.

A)System.halt(0); B)System.quit(0); C)System.terminate(0); D)System.stop(0); E)System.exit(0); 15)Which of the Boolean expressions below is incorrect? (Choose all that apply.) A)(x != 0) || (x = 0) B)(true) && (3 => 4) C)(-10 < x < 0)

D)!(x > 0) && (x > 0) E)(x > 0) || (x < 0)

16)Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? A)((x < 100) && (x > 1)) && (x < 0) B)1 < x < 100 && x < 0 C)(1 > x > 100) || (x < 0)

D)((x < 100) && (x > 1)) || (x < 0)

17)Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)? A)9 B) 11 C) 10

18)Suppose x=10 and y=10 what is x after evaluating the expression (y > 10) && (x++ > 10)? A)11 B) 10 C) 9

19)Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x-- > 10)? A)11 B) 9 C) 10

20)Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10)? A)10 B) 9 C) 11

21)To check whether a char variable ch is an uppercase letter, you write ________. A)('A' <= ch <= 'Z') B) (ch >= 'A' || ch <= 'Z')

C)(ch >= 'A' && ch <= 'Z') D) (ch >= 'A' && ch >= 'Z') 22)Analyze the following code: if (x < 100) && (x > 10)

System.out.println(\

- 11 -

A)The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses and the println(…) statement must be put inside a block.

B)The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses.

C)The statement compiles fine.

D)The statement compiles fine, but has a runtime error. 23)What is the output of the following code? char ch = 'F';

if (ch >= 'A' && ch <= 'Z') System.out.println(ch); A)f B) F C) F f D) nothing

24)What is y after the following switch statement is executed? x = 3;

switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; }

A)4 B) 3 C) 1 D) 2

25)What is the printout of the following switch statement? char ch = 'a'; switch (ch) { case 'a': case 'A':

System.out.print(ch); break; case 'b': case 'B':

System.out.print(ch); break; case 'c': case 'C':

System.out.print(ch); break; case 'd': case 'D':

System.out.print(ch); }

A)a B) abc C) abcd D) aa E) ab

26)What is the printout of the following switch statement? char ch = 'b'; switch (ch) { case 'a':

System.out.print(ch); case 'b':

System.out.print(ch); case 'c':

- 12 -

System.out.print(ch); case 'd':

System.out.print(ch); }

A)abcd B) bb C) bcd D) bbb E) b

27)Analyze the following program fragment: int x;

double d = 1.5;

switch (d) {

case 1.0: x = 1; case 1.5: x = 2; case 2.0: x = 3; }

A)The program has a compile error because the required default case is missing in the switch statement.

B)The switch control variable cannot be double.

C)The program has a compile error because the required break statement is missing in the switch statement. D)No errors.

28)What is y after the following statement is executed? x = 0;

y = (x > 0) ? 10 : -10; A)0 B)-10 C)10 D)20

E)Illegal expression

29)Analyze the following code fragments that assign a boolean value to the variable even. Code 1:

if (number % 2 == 0) even = true; else

even = false; Code 2:

even = (number % 2 == 0) ? true: false; Code 3:

even = number % 2 == 0;

A)All three are correct, but Code 1 is preferred. B)All three are correct, but Code 3 is preferred. C)All three are correct, but Code 2 is preferred.

D)Code 3 has a compile error, because you attempt to assign number to even.

E)Code 2 has a compile error, because you cannot have true and false literals in the conditional expression.

- 13 -

30)What is the output of the following code? boolean even = false;

System.out.println((even ? \A)false B) true C)true false D) nothing

31)Which of the following are valid specifiers for the printf statement? (Choose all that apply.) A)L B).2e C)b D)m E)%8.2d

32)The statement System.out.printf(\ A)1234.6 B)123.5 C)123.4 D)1234.56 E)1234.5

33)The statement System.out.printf(\ A)0.1e+04 B)0.123456e+04 C)0.123e+04 D)1.23+03 E)1.2e+03 34)The statement System.out.printf(\ A)12345.6 B) 123456 C) 12345 D) 23456

35)The statement System.out.printf(\123456) outputs ________. (Note: * represents a space)

A)23456***** B) 123456**** C)****123456 D) 12345***** 36)Analyze the following code: int i = 3434; double d = 3434;

System.out.printf(\

A)The code compiles and runs fine to display 3434 3434.0. B)The code compiles and runs fine to display 3434.0 3434.0.

C)i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.

37)The order of the precedence (from high to low) of the operators +, *, &&, ||, & is: ______ A)&, ||, &&, *, + B)&&, ||, &, *, + C)*, +, &, ||, && D)*, +, &&, ||, & E)*, +, &, &&, ||

38)Which of the following operators are right-associative? A)= B) * C) % D) + E) &&

39)What is the value of the following expression? true || true && false A)true B) false

40)Which of the following statements are true? (Choose all that apply.) A)(x > 0 || x < 10) is same as ((x > 0) || (x < 10))

B)(x > 0 && x < 10) is same as ((x > 0) && (x < 10))

C)(x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 && y < 0)) D)(x > 0 || x < 10 && y < 0) is same as ((x > 0 || x < 10) && y < 0)

1)D 2)D 3)A 4)C 5)B 6)D 7)B 8)C 9)D 10)C 11)B 12)B 13)B 14)E 15)A, B, C 16)D 17)C 18)B 19)C 20)A 21)C 22)B 23)B 24)D 25)A 26)D 27)B 28)B 19)B 30)A 31)A, B, C, D 32)A 33)E 34)B 35)C 36)C 37)E 38)A 39)A 40)A, B, C

Chapter4

1)How many times will the following code print \

- 14 -

int count = 0;

while (count < 10) {

System.out.println(\ count++; }

A)8 B) 9 C) 0 D) 11 E) 10

2)Analyze the following code. (Choose all that apply.) int count = 0;

while (count < 100) { // Point A

System.out.println(\ count++; // Point B }

// Point C

A)count < 100 is always true at Point A B)count < 100 is always true at Point C C)count < 100 is always true at Point B D)count < 100 is always false at Point B E)count < 100 is always false at Point C

3)How many times will the following code print \int count = 0;

while (count++ < 10) {

System.out.println(\}

A)0 B) 9 C) 8 D) 11 E) 10

4)How many times will the following code print \int count = 0; do {

System.out.println(\ count++;

} while (count < 10);

A)9 B) 0 C) 10 D) 11 E) 8

5)How many times will the following code print \int count = 0; do {

System.out.println(\} while (count++ < 10); A)8 B) 9 C) 0 D) 10 E) 11

6)How many times will the following code print \int count = 0; do {

System.out.println(\} while (++count < 10);

- 15 -


java题库(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:激发幼儿在科学活动中的探究兴趣

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: