Java 面向对象程序设计 错题整理 chapter 05

博客讨论了关于程序中可能出现的问题。第一部分展示了一个可能陷入无限循环的for循环,因为条件`d < 10`始终为真。第二部分提到可以将while循环转化为for循环,这是一个常见的编程实践。第三部分指出在某些情况下,编写程序时可以避免使用`break`或`continue`语句。
摘要由CSDN通过智能技术生成

17.

Analyze the following statement:

double sum = 0;

for (double d = 0; d < 10;) {

  d += 0.1;

  sum += sum + d;

}

 回答错误

单选题 (2 分) 0 分

  1.  A.

    The program compiles and runs fine.

  2.  B.

    The program has a compile error because the control variable in the for loop cannot be of the double type.

  3.  C.

    The program runs in an infinite loop because d<10 would always be true.

  4.  D.

    The program has a compile error because the adjustment is missing in the for loop.

30.

You can always convert a while loop to a for loop.

 回答错误

判断题 (2 分) 0 分

  1.  A.

    true

  2.  B.

    false

 

41.

You can always write a program without using break or continue in a loop.

 回答错误

判断题 (2 分) 0 分

  1.  A.

    false

  2.  B.

    true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值