Loading...
Loading...
A geometry app checks three stick lengths. Three lengths form a triangle only if each one is less than the sum of the other two. If they do, the triangle is:
Equilateral when all three sides are equal;Isosceles when exactly two sides are equal;Scalene when all sides are different.Read the three lengths and print the type, or Not a triangle.
Equilateral, Isosceles, Scalene or Not a triangle.Example 1
Input
3 4 5
Output
Scalene
A valid triangle with all sides different.
Example 2
Input
5 5 8
Output
Isosceles
Two equal sides.
Example 3
Input
1 2 3
Output
Not a triangle
1 + 2 equals 3, so the sticks lie flat: not a triangle.
Try the problem first. Open one hint at a time.
Check whether it is a triangle at all before deciding the type.
You need three checks joined with &&: a + b > c, a + c > b and b + c > a.
Read the sides as long: two sides of 10^9 add up to more than an int can hold.
For the type, test "all three equal" first, then "any two equal" with ||.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor