int pos =1;
int neg =- 1;
int sum;
String result;
sum = (Integer.signum(pos)+Integer.signum(neg));
System.out.println(result = sum>0?"Both Positive":sum<0?"Both Negative":"One is negative, one positive");
if(Integer.signum(a) == -1){System.out.println(" a is negative");}
else{System.out.println("a is positive");}
what is the return type of the signum()
public boolean posNeg(int a, int b, boolean negative) {
if(Integer.signum(a)!=Integer.signum(b)){
return true;
}
if(Integer.signum(a)==-1 & Integer.signum(b)==-1 & negative==true){
return true;
}
return false;
}
Returns the signum function of the specified int value
public boolean posNeg(int a, int b, boolean negative) {
if(negative==true){
return (a<0&& b<0);
}
if((a>0&&b<0)||(a<0&&b>0)){
return true;
}
return false;
}
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));
}
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
firstswap challenge | 20 | 67 | |
eclipse formatting | 6 | 72 | |
Java / Linux and Regular Expressions | 11 | 70 | |
MySqlDump not dumping triggers | 1 | 17 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
20 Experts available now in Live!