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 2 of 2

Thread: Checking to see whether a triangle is obtuse isosceles or acute isosceles.

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Checking to see whether a triangle is obtuse isosceles or acute isosceles.

    obtuse: any two side lengths where the sum of their squares is less than the square of the other side length
    right: any two side lengths where the sum of their squares is equal to the square of the other side length
    acute: a triangle is an acute triangle if it is neither a right triangle nor an obtuse triangle
    isosceles : any two sides are the same length
    if ((Side1 == Side2 || Side1 == Side3 || Side2 == Side3) &&
    ((Math.pow(Side1,2) + Math.pow(Side2,2)) < Math.pow(Side3,2) ||
    (Math.pow(Side3,2) + Math.pow(Side1,2)) < Math.pow(Side2,2) ||
    (Math.pow(Side3,2) + Math.pow(Side2,2)) < Math.pow(Side1,2) ))

    {
    return "obtuse isosceles" ;
    }

    if ((Side1 == Side2 || Side1 == Side3 || Side2 == Side3) &&
    ((Math.pow(Side1,2) + Math.pow(Side2,2)) > Math.pow(Side3,2) ||
    (Math.pow(Side3,2) + Math.pow(Side1,2)) > Math.pow(Side2,2) ||
    (Math.pow(Side3,2) + Math.pow(Side2,2)) > Math.pow(Side1,2)))
    {
    return "acute isosceles" ;

    Am I atleast on the right track? Can you help me fix it? Can you interpret the code I wrote. Like for the first one, the program checks to see whether it's an isosceles ((Side1 == Side2 || Side1 == Side3 || Side2 == Side3) is this correct? And then it checks to see whether the sum of the two squared sides is less than the other squared side &&
    ((Math.pow(Side1,2) + Math.pow(Side2,2)) < Math.pow(Side3,2) ||
    (Math.pow(Side3,2) + Math.pow(Side1,2)) < Math.pow(Side2,2) ||
    (Math.pow(Side3,2) + Math.pow(Side2,2)) < Math.pow(Side1,2) ))
    is that correct. I'm having trouble understanding this if else stuff. Can you think of a more efficient way of testing to see whether the triangle is obtuse/acute?


  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Checking to see whether a triangle is obtuse isosceles or acute isosceles.

    Hi michael305rodri ,
    I tried the posted code, and its working fine, you are on the right track.
    the first bracket in the if condition checks whether the 2 sides are same and second brackets checks for sum of square.
    result of first bracket condition is ANDed with result of second bracket condition which decides the type of triangle.

Similar Threads

  1. help me draw a triangle....
    By beandip408 in forum Object Oriented Programming
    Replies: 10
    Last Post: October 28th, 2010, 05:49 PM
  2. [HELP] TRIANGLE!
    By kramista in forum Loops & Control Statements
    Replies: 10
    Last Post: July 29th, 2010, 12:58 PM
  3. ASCII Triangle
    By physics in forum Loops & Control Statements
    Replies: 1
    Last Post: March 27th, 2010, 06:39 AM
  4. Triangle issues
    By FrEaK in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 24th, 2010, 08:49 AM
  5. Triangle Question
    By Leeds_Champion in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 29th, 2009, 11:33 PM