Solved

Analyze the Following Code Fragments That Assign a Boolean Value

Question 18

Multiple Choice

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 3 has a syntax error, because you attempt to assign number to even.
B) Code 2 has a syntax error, because you cannot have true and false literals in the conditional expression.
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.

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents