Logical Error In Range Check
The code segment below is intended to determine if an integer value is in the range of 5 to 10, inclusive.
public class RangeCheck {
public static void main(String[] args) {
int value = 7;
if(value >= 5 && value >= 10)
System.out.println("Value is between 5 and 10");
else
System.out.println("Value is not between 5 and 10");
}
}
Which statement best describes the logical error in the if statement’s condition?
A
Declaring variable value as a byte instead of an int.
B
Failing to include an equality check for the lower bound.
C
Using “value >= 10” instead of “value <= 10” in the condition.
D
Replacing the logical AND (&&) with OR (||) in the condition.
Question Leaderboard
Not enough data yet to show leaderboard.
