Triangle Classifier
Completed
Read three side lengths. Print invalid if they can't form a triangle, otherwise equilateral, isosceles or scalene.
Input
Three positive integers.
Output
One word.
Example
Input
3 3 3
Output
equilateral
Editor
Java
Hints
Sort the sides so the longest is last.
Valid if the two shorter sides add up to more than the longest.
Solution explanation
Sorting removes the need to check every arrangement of the sides.
Show solution
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] s = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
Arrays.sort(s);
if (s[0] + s[1] <= s[2]) {
System.out.println("invalid");
} else if (s[0] == s[2]) {
System.out.println("equilateral");
} else if (s[0] == s[1] || s[1] == s[2]) {
System.out.println("isosceles");
} else {
System.out.println("scalene");
}
}
}