云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 面向对象编程基础习题及答案

面向对象编程基础习题及答案

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 11:00:52

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 页

搜索更多关于: 面向对象编程基础习题及答案 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

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 prin

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com