JAVA program that checks if a triangle is scalene, isosceles, equilateral, or not a triangle

You should check for not a triangle condition first. As below:

static void checkTriangle(int x, int y, int z) 
{ 

    // Check for not a triangle 
    if (x + y < z || x + z < y || y + z > x) {
        System.out.println("Not a triangle");
    } else {

    // Check for equilateral triangle 
    if (x == y && y == z ) 
        System.out.println("Equilateral Triangle"); 

    // Check for isoceles triangle 
    else if (x == y || y == z || z == x ) 
        System.out.println("Isoceles Triangle"); 

    // Check for scalene triangle
    else if (x != y || y!= z || z != x)
        System.out.println("Scalene Triangle");
    }
} 

public static void main(String[] args) {
    { 

        int x = 1, y = 1, z = 30; 

        checkTriangle(x, y, z); 
    } 
} 
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top