Try this,
public class TriangleType {
public static void main(String[] args) {
int side1 = 3;
int side2 = 4;
int side3 = 5;
int result = checkTriangleType(side1, side2, side3);
switch (result) {
case 1:
System.out.println("Scalene Triangle");
break;
case 2:
System.out.println("Isosceles Triangle");
break;
case 3:
System.out.println("Equilateral Triangle");
break;
case 4:
System.out.println("Error: Not a valid triangle");
break;
}
}
public static int checkTriangleType(int side1, int side2, int side3) {
if (side1 > 0 && side2 > 0 && side3 > 0) {
if ((side1 + side2 > side3) && (side2 + side3 > side1) && (side3 + side1 > side2)) {
if (side1 == side2 && side2 == side3) {
return 3; // Equilateral Triangle
} else if (side1 == side2 || side2 == side3 || side3 == side1) {
return 2; // Isosceles Triangle
} else {
return 1; // Scalene Triangle
}
} else {
return 4; // Error: Not a valid triangle
}
} else {
return 4; // Error: Not a valid triangle (negative side length)
}
}
}