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

3.14.

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is correct?

I: 

if (age < 16) 

  System.out.println("Cannot get a driver's license");

if (age >= 16) 

  System.out.println("Can get a driver's license");

II:

if (age < 16) 

  System.out.println("Cannot get a driver's license");

else 

  System.out.println("Can get a driver's license");

III:

if (age < 16) 

  System.out.println("Cannot get a driver's license");

else if (age >= 16) 

  System.out.println("Can get a driver's license");

IV:

if (age < 16) 

  System.out.println("Cannot get a driver's license");

else if (age > 16) 

  System.out.println("Can get a driver's license");

else if (age == 16) 

  System.out.println("Can get a driver's license");

 回答错误

多选题 (2 分) 0 分

  1.  A.

    IV

  2.  B.

    I

  3.  C.

    II

  4.  D.

    III

16.

The conditional operator ? : is a ______

 回答错误

单选题 (1 分) 0 分

  1.  A.

    ternary operator(三元运算符)

  2.  B.

    unary operator

  3.  C.

    binary operator

18.

Which of the Boolean expressions below is incorrect?

 回答错误

多选题 (2 分) 0 分

  1.  A.

    (true) && (3 => 4)

  2.  B.

    (x != 0) || (x = 0)

  3.  C.

    (x > 0) || (x < 0)

  4.  D.

    (-10 < x < 0)

  5.  E.

    !(x > 0) && (x > 0)

23.

You can cast a Boolean value to an int, or an int to Boolean.

判断题 (2 分) 2 分

  1.  A.

    true

  2.  B.

    false

两者在Java中不可以相互转换

27.

The order of the precedence (from high to low) of the operators binary +, *, &&, ||, ^ is:

单选题 (1 分) 1 分

  1.  A.

    &&, ||, ^, *, +

  2.  B.

    ^, ||, &&, *, +

  3.  C.

    *, +, ^, &&, ||

  4.  D.

    *, +, ^, ||, &&

  5.  E.

    *, +, &&, ||, ^

29.

System.exit(0) can be used to terminate the program.

判断题 (2 分) 2 分

  1.  A.

    true

  2.  B.

    false

40.

What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?

单选题 (1 分) 1 分

  1.  A.

    false

  2.  B.

    true

  3.  C.

    There is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true.

emmm,我运行的结果是false。。不晓得c选项啥意思。。。

44.

The binary operator + is left-associative.

判断题 (2 分) 2 分

  1.  A.

    true

  2.  B.

    false

45.

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;

 回答错误

单选题 (1 分) 0 分

  1.  A.

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

  2.  B.

    All three are correct, but Code 1 is preferred.

  3.  C.

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

  4.  D.

    All three are correct, but Code 3 is preferred.

  5.  E.

    All three are correct, but Code 2 is preferred.

53.

Which of the following operators are right-associative.

单选题 (1 分) 1 分

  1.  A.

    %

  2.  B.

    =

  3.  C.

    + (binary +)

  4.  D.

    &&

  5.  E.

    *

57.

Which of the following are so called short-circuit operators?

多选题 (2 分) 2 分

  1.  A.

    ||

  2.  B.

    &&

  3.  C.

    &

  4.  D.

    |

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值