Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Help with logical operators

1. ## Help with logical operators

hi everyone I am having trouble getting my logical operators to work correctly, I believe I am making an error somewhere that I cannot find myself. I created a method called "type" where I am trying to determine the type of triangle by comparing side 1, side 2, and side 3. which i shortened to s1, s2 and s3. It seems that even when I enter all three sides the same, it still claims that it is an Isosceles Triangle when it should say that it is a Equilateral Triangle. Any help would be appreciated, thanks.

```public static void type(double s1, double s2, double s3){

if(s1 == s2 || s1 == s3 || s2 == s3){
System.out.println("The triangle is Isosceles since it has two equal length sides.");
}
else if(s1 == s2 && s1 == s3 && s2 == s3){
System.out.println("The triangle is Equilateral since it has equal length on all three sides.");
}
else {
System.out.println("The triangle is Scalene with no equal sides.");
}
}```

2. ## Re: Help with logical operators

Switch your Isosceles and Equilateral if loops. With the code as it is right now, If the triangle is an Equilateral, the first if loop will find at least 2 sides equal and return true, and you will get the Isosceles message. Check for Equilateral before the Isosceles check.

Thank you!