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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help with logical operators

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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. #2
    Junior Member
    Join Date
    Apr 2012
    Location
    Missouri, United States
    Posts
    17
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Default 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.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with logical operators

    Thank you!

Similar Threads

  1. confused on what this problem is asking for (bitwise operators)
    By mmholdford in forum Java Theory & Questions
    Replies: 3
    Last Post: February 9th, 2012, 06:52 AM
  2. Evaluation of operators in expressions.
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 7
    Last Post: September 23rd, 2011, 07:23 PM
  3. Logical Operators
    By truebluecougarman in forum Java Theory & Questions
    Replies: 3
    Last Post: January 22nd, 2011, 06:26 PM
  4. Need Help with Operators/ logic
    By codekiller in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2010, 09:25 AM
  5. Proper output for Non preemptive scheduling problem
    By haygaurav in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 4th, 2009, 07:58 AM