lordzee - 2 months ago 25

Java Question

I made a program that asks the user for 3 lengths and determines if it is equilateral,scalene, isosceles. I want to know how to calculate angles(all 3 sides are given) in Java so that the program determines if it is obtuse or acute or right-angled.Please help me out.

Answer

As you know the sides of the triangle, you can find the angles just by following steps below...

- use The Law of Cosines first to calculate one of the angles
- then use The Law of Cosines again to find another angle
- and finally use angles of a triangle add to 180° to find the last angle.

In java you can use `Math.acos(val)`

to calculate the Inverse Cosine.