WAP :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.
public class NegativePositive {
public static void posNeg(int a,int b, boolean neg)
{
if((a<0&b>0&neg==false)|(a>0&b<0&neg==false))
{
System.out.println(true);
}
else if(a<0&b<0&neg==true)
System.out.println(true);
else
System.out.println(false);
} public static void main(String[] args) {
posNeg(-5,-1,true);
}
}
No comments:
Post a Comment
Please post your comments. Your comments make us to write more programs for you.