| preferred AP College board partner for AP classes
medium Solved by 7 students
Equivalent Boolean Expressions
< Prev
Next >

Which of the following statements assigns the same value to flag2 as the code segment assigns to flag for all values of x?

Consider the following code segment.

int x = /* initial value not shown */;
boolean flag = false;
if (x >= 10) {
    if (x <= 50) {
        flag = true;
    }
} else {
    if (x <= 0) {
        flag = true;
    }
}

Which of the following statements assigns the same value to flag2 as the code segment assigns to flag for all values of x?

A

boolean flag2 = (x >= 10 && x <= 0) || (x <= 50);

B

boolean flag2 = (x >= 10) || (x <= 0);

C

boolean flag2 = (x >= 10 && x <= 50) || (x <= 0);

D

boolean flag2 = (x < 50) && (x >= 10 || x <= 0);

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1hitrishabhatia13 0m 00s 80
#2y.seong202712 1m 38s -8
#3bommasam00012 9h 30m -34,142
Items per page:
10
1 – 3 of 3

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy