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;
a. Code 2 has a compile error, because you cannot have true and false literals in the conditional expression.
b. Code 3 has a compile error, because you attempt to assign number to even.
c. All three are correct, but Code 1 is preferred.
d. All three are correct, but Code 2 is preferred.
e. All three are correct, but Code 3 is preferred.
e Code 3 is the simplest. Code 1 and Code 2 contain redundant code.
You might also like to view...
MC Counting loops should be controlled with______ values.
a) floating-point. b) integer. c) string. d) None of the above.
A nice performance feature of lazy evaluation is the ability to perform________ evaluation, that is, to stop processing the stream pipeline as soon as the desired result is available.
a. premature b. short circuit c. terminal d. intermediate
The __________________ is the central organization that tracks and disperses IP addresses.
Fill in the blank(s) with the appropriate word(s).
Press the ____________________ key to add an absolute reference symbol ($) to a formula.
Fill in the blank(s) with the appropriate word(s).