第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/5/23 22:12:39 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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 页

搜索更多关于: 面向对象编程基础习题及答案 的文档
面向对象编程基础习题及答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c8zw199vcmo44p5d1brid_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top