B. -1
C. 0
D. None of the above
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); }
47. What is the printout of the following switch statement?
A. abcd B. a C. aa D. ab E. abc
48. Analyze the following code.
int x = 0;
int y = ((x<100) & (x>0)) ? 1: -1;
A. The code has a syntax error because & must be &&. B. y becomes 1 after the code is executed. C. y becomes -1 after the code is executed. D. None of the above.
49. Which of the following is not a valid boolean expression.
A. (1 < x < 100)
B. (x = 1) || (x != 1) C. a, b are all correct D. a, b are all wrong
50. Which of the following expression is equivalent to (x > 1).
A. x >= 1
第 9 页 共 34 页
B. !(x <= 1)
C. !(x = 1) D. !(x < 1)
E. None of the above
51. Analyze the following two code fragments.
(i)
int x = 5;
if (0 < x) && (x < 100)
System.out.println(\(ii)
int x = 5;
if (0 < x && x < 100)
System.out.println(\
A. The first fragment has a syntax error.
B. The second fragment has a syntax error. C. Both fragments produce the same output.
D. Both fragments compile, but produce different result. E. None of the above.
52. Analyze the following fragment.
double x = 0; double d = 1; switch (d + 4) {
case 5: x++; case 6: --x; }
A. The required break keyword is missing in the switch statement. B. The required default keyword is missing in the switch statement C. The switch control variable cannot be double D. a, b, and c are all correct. E. a, b, and c are all incorrect. 53. Analyze the following code.
int x = 0; if (x > 0); {
System.out.println(\}
第 10 页 共 34 页
A. The symbol x is always printed.
B. The value of variable x is always printed. C. Nothing is printed because x > 0 is false. D. None of the above.
54. Which of the loop statements always have their body executed at least once.
A. The while loop B. The do-while loop
C. The for loop
D. None of the above 55. Analyze the following code.
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 B C. count < 100 is always false at Point B D. count < 100 is always true at Point C 56. What is the value in count after the following loop is executed?
int count = 0; do {
System.out.println(\} while (count++ < 9); System.out.println(count);
A. 8 B. 9 C. 10 D. 11
57. What is the output for y?
int y = 0;
for (int i = 0; i<10; ++i) { y += i; }
第 11 页 共 34 页
System.out.println(y);
A. 10 B. 11 C. 12 D. 45
58. Analyze the following code.
int x = 1;
while (0 < x) & (x < 100)
System.out.println(x++);
A. The loop runs for ever.
B. The code does not compile because the loop body is not in the
braces.
C. The code does not compile because (0 < x) & (x < 100) is not
enclosed in a pair of parentheses. D. The number 1 to 99 are displayed. E. The number 2 to 100 are displayed. 59. Analyze the following code.
double sum = 0;
for (double d = 0; d < 10; sum += sum + d) {
d += 0.1; }
A. The program has a syntax error because the adjustment statement is incorrect in the for loop.
B. The program has a syntax error because the control variable in
the for loop cannot be of the double type. C. The program compiles but does not stop because d would always
be less than 10. D. The program compiles and runs fine. 60. Analyze the following fragment:
double sum = 0; double d = 0; while (d != 10.0) { d += 0.1; sum += sum + d; }
A. The program does not compile because sum and d are declared
第 12 页 共 34 页