Reputation: 23
Sorry if this is a primitive topic, I have a professor that doesn't speak english and I'm rather lost.
I'm trying to declare a method that checks if a triangle is equilateral. It keeps telling me that I'm comparing a boolean to an int in my if statement. side1, side2, and side3 are all int types.
public boolean is_equilateral(){
if (side1 == side2 == side3){
return true;
}
return false;
}
Thanks for the help ahead of time!
Upvotes: 1
Views: 508
Reputation: 167
Use
if((side1 == side2) && (side2 == side3))
instead of
if(side1 == side2 == side3)
Upvotes: 1
Reputation: 1807
The expression side1 == side2
evaluates to boolean, thus you cannot compare it to another int. But you can do:
if((side1 == side2) && (side2 == side3)) {
...
}
Upvotes: 4
Reputation: 44439
In your comparison if (side1 == side2 == side3)
it will first compare side1 == side2
, resulting in a boolean.
Afterwards it will compare the first result (boolean
) with the last element (int
), thus giving an error.
You can't compare a boolean
to an int
.
Upvotes: 6