Created
December 10, 2016 15:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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