# comparing sign of two numbers

Hi,
I was going through below link
http://codingbat.com/prob/p192082

I wrote solution as below

public boolean icyHot(int temp1, int temp2) {
if(temp1<0 && temp2>100)
{
return true;
}

if(temp1>0 && temp2<100)
{
return true;
}
return false;
}

I saw given solution as below

public boolean icyHot(int temp1, int temp2) {
if ((temp1 < 0 && temp2 > 100) || (temp1 > 100 && temp2 < 0)) {
return true;
} else {
return false;
}
// Could be written as: return ((temp1 < 0 && ...));
}

can the natural flow of next line can be written always after || (which is the only difference i see from my program.

LVL 7
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
if( a ){
return true;
}
if( b ){
return true;
}
return false;

is equivalent to

if( (a) || (b) ){
return true;
}else{
return false;
}

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Author Commented:
``````public boolean icyHot(int temp1, int temp2) {

if( (a) || (b) ){
return true;
}

}
``````

why above code wont compile?  Giving return statement in if loop alone is not sufficient. Do i need to give outside if loop also?
Commented:
Because you don't have a return statement outside of the if block. Think about it this way:  If your code never entered the if block, what would it return? We cannot tell because you have not defined anything.
Commented:
Because you didn't define a and b

(The equivalent form would also not compile for equivalent reason)

I see no loop in your code, so I don't understand your last comment.
Commented:
Your original solution is fine and just as good as the "given solution" on the website.

As you said, the only difference is that they put the two conditions together with an "||" (or) and you broke them out into separate lines.  Either approach is fine.

I think you misunderstood what ozo posted.  He was basically saying that the two solutions are equivalent (he just said it in code).

Doug
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.