I'm almost done! I am supposed to make a program that allows a user to input the sides of a triangle and print out whether it's an equilateral, obtuse/acute isosceles, or no triangle. Right triangle isosceles doesn't have to be tested for since my assignment requires only ints.
public String triangle(int Side1, int Side2, int Side3)
{
if(Side1 == Side2 && Side1 == Side3 && Side2 == Side3)
{
return "equilateral";
}
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" ;
}
else
{
return "No triangle" ;
}
I'm almost done! I am supposed to make a program that allows a user to input the sides of a triangle and print out whether it's an equilateral, obtuse/acute isosceles, or no triangle. Right triangle isosceles doesn't have to be tested for since my assignment requires only ints.
Basically, If side1^2 + side2^2 < side3^2 then it is an obtuse
If side1^2 +side2^2 is greater than side3^2 then it is acute.
When I input 2, 3, 2 it says i got an obtuse isosceles
however when i input 3,4,3 it says i got an acute isosceles...
Wtf?
2^2 + 3^2 > 2^2 so this should be acute not obtuse....
3^2 + 4^2 > 3^2 this was correct.
But what's wrong? I thought maybe it was multiplying the same lengths first and than comparing them to the other side. For example,
2^2 +2^2 < 3^2 which yields obtuse which is correct
3^2 + 3^2 > 4^2 which yields acute which is correct
but why would it be doing this?
Thanks you so much