Equivalent Boolean Expressions
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);
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | hitrishabhatia | 1 | 3 | 0m 00s | 80 |
| #2 | y.seong2027 | 1 | 2 | 1m 38s | -8 |
| #3 | bommasam000 | 1 | 2 | 9h 30m | -34,142 |
Items per page:
10
1 – 3 of 3
APFIVE