Write me a function that receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type (1=scalene, 2=isosceles, 3=equilateral, 4=error).
/*****************************************************************
Method: getTriangleType()
Input: three integer sides a, b, c.
Return: 1 - scalene, 2 - isosceles, 3 - equilateral, 4 - error.
*****************************************************************/
public int getTriangleType(int a, int b, int c) {
if ((a + b) < c) {
/* If sum of any of two sides less than third side, than it cannot be
a triangle. I chose (a + b) < c, but (a + c) < b or (b + c) < a would
work too. */
return 4;
} else if(a == b || a == c || b == c) {
/* If two of the three sides are equal than we check for equilateral. */
if (a == b && a == c) {
/*Here you can also use (b == a && b == c) or (c == a && c == b). */
return 3;
} else {
/* If it is not equilateral, than it is isosceles*/
return 2;
}
} else {
/* Only scalene triangle left. */
return 1;
}
}
Как развивать веб-проекты в 2026 году: технологии, контент E-E-A-T и факторы доверия
Современные инструменты для криптотрейдинга: как технологии помогают принимать решения
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники