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: Checking to see whether a triangle is obtuse isosceles or acute isosceles.

1. ## 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?  Reply With Quote

3. ## 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.  Reply With Quote