Skip to content

Instantly share code, notes, and snippets.

@nazmul202101
Created December 10, 2016 15:48
Show Gist options
  • Save nazmul202101/eb8b4bf2f0f018101b242af9dffcca2d to your computer and use it in GitHub Desktop.
Save nazmul202101/eb8b4bf2f0f018101b242af9dffcca2d to your computer and use it in GitHub Desktop.
Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
//Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
//posNeg(1, -1, false) → true
//posNeg(-1, 1, false) → true
//posNeg(-4, -5, true) → true
public boolean posNeg(int a, int b, boolean negative) {
if(a<0 && b>0 && negative==false){
return true;
}
else if(a>0 && b<0 && negative==false){
return true;
}
else if(a<0 && b<0 && negative==true){
return true;
}
else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment