Skip to main content

code

2 replies [Last post]
utopiajk
Offline
Joined: 2010-08-28

Here is the question: Given 2 int values, return true if one is negative and one is positive. Unless the parameter "negative" is true, then they both must be negative.

it return true only if one is negative and one is positive ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
utopiajk
Offline
Joined: 2010-08-28

Given answer :

public boolean posNeg(int a, int b, boolean negative) {
if (negative) {
return (a < 0 && b < 0);
}
else {
return ((a < 0 && b > 0) || (a > 0 && b < 0));
}
}

utopiajk
Offline
Joined: 2010-08-28

i think you can't return true, if the parameter negative is true. right?