"Write the correct logic expression (that could be used as a Java conditional expression) that evaluates to true if the number x is between 1 and 100 (both exclusive) or the number is negative."

I have this answer:

if ((x >=1 && x <= 100) || x < 0) { }

But I am being told this is wrong for this reason:

Mack Grill wrote:I have this answer:
if ((x >=1 && x <= 100) || x < 0) { }

I hope I'm not muddying the waters here, but when you think about compound conditions, it's a good idea to try and eliminate the most likely quickest.
All other things being equal (which they often aren't)
x < 0 is true for a lot more values than
(x >=1 && x <= 100) and its also quicker to check, so
if (x < 0 || (x >=1 && x <= 100)) is likely to run faster than what you had. I actually find it easier to read too.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com