120k views
4 votes
Given that the variables x and y have already been declared and assigned values, write an expression that evaluates to true if x is non-negative (that is, positive or zero) or y is negative?

1 Answer

1 vote

Final answer:

To determine whether x is non-negative or y is negative, use the logical OR operator in an if statement with (x >= 0) || (y < 0) expression.

Step-by-step explanation:

To determine whether x is non-negative or y is negative, we can use the logical OR operator (||) in an if statement. The expression would be: (x >= 0) || (y < 0). This expression will evaluate to true if either x is non-negative or y is negative.

For example, if x = 0.0216 and y = -0.0224, the expression (0.0216 >= 0) || (-0.0224 < 0) would evaluate to true, since x is non-negative.

User Bhavesh Vala
by
9.1k points