Determining triangle type from three integer inputs The logic is simple, but I was wondering if anyone could help with rewriting the conditional logic. Also, the only error conditions I can think of are the sides should not be equal to or less than zero. Are there any other error conditions that seem to occur to you?

public class TriangleType {

    static Triangle getType(int a, int b, int c)
    {
        if(a&lt;=0||b&lt;=0||c&lt;=0)
            throw new IllegalArgumentException("Length of sides cannot be equal to or less than zero");

        if(a==b&amp;&amp;b==c&amp;&amp;c==a)
            return Triangle.EQUILATERAL;
        else if((a==b)||(b==c)||(c==a))
            return Triangle.ISOSCELES;
        else if(a!=b&amp;&amp;b!=c&amp;&amp;c!=a)
            return Triangle.SCALENE;
        else
            return Triangle.ERROR;
    }


    public static void main(String[] args)
    {
        System.out.println(TriangleType.getType(13, 13, 0));

    }
}

enum Triangle
{
ISOSCELES(0),
EQUILATERAL(1),
SCALENE(2),
ERROR(3);

private int n;
Triangle(int n)
{this.n = n;}
}
You could encapsulate the conditions in a PotentialTriangle class. Note that the fields are of type long to avoid overflow when calculating whether triangle inequality is violated.

public class PotentialTriangle {
    private final long a, b, c;

    public PotentialTriangle(int sideA, int sideB, int sideC) {
        a = sideA;
        b = sideB;
        c = sideC;
    }

    public boolean isAnySideTooShort() {
        return a &lt;= 0 || b &lt;= 0 || c &lt;= 0;
    }

    public boolean violatesTriangleInequality() {
        return a &gt; b + c || b &gt; a + c || c &gt; a + b;
    }

    public boolean areSidesEqual() {
        return a == b &amp;&amp; b == c;
    }

    public boolean areAtLeastTwoSidesEqual() {
        return a == b || b == c || c == a;
    }
}


This would vastly simplify your enum selection code, which I would put directly into the enum:

public enum TriangleType {
    ISOSCELES,
    EQUILATERAL,
    SCALENE;

    public static TriangleType ofPotentialTriangle(PotentialTriangle triangle) {
        throwIf(triangle.isAnySideTooShort(), 
                "Length of sides cannot be equal to or less than zero");
        throwIf(triangle.violatesTriangleInequality(), 
                "Sum of any two sides must be larger than the remaining side");

        if (triangle.areSidesEqual()) {
            return EQUILATERAL;
        }
        if (triangle.areAtLeastTwoSidesEqual()) {
            return ISOSCELES;
        }
        return SCALENE;
    }

    private static void throwIf(boolean condition, String message) {
        if (condition) {
            throw new IllegalArgumentException(message);
        }
    }
}