Triangle

mail@pastecode.io avatar
unknown
plain_text
2 years ago
757 B
2
Indexable
Never
package main;

/**
* Triangle class.
*
* @author Chi Nhan
*/
public class Triangle {
  private int canhA;
  private int canhB;
  private int canhC;

  /**
   * Constructor.
   */
  public Triangle(int canhA, int canhB, int canhC) {
    this.canhA = canhA;
    this.canhB = canhB;
    this.canhC = canhC;
  }

  /**
   * check if 3 numbers is a triangle.
   */
  public int isTriangle() {
    if ((canhA < (canhB + canhC)) && ((canhA + canhB) > canhC) && ((canhA + canhC) > canhB)) {
      if (canhA == canhB && canhB == canhC) {
        return 2;
      } else if (canhA == canhB || canhB == canhC || canhA == canhC) {
        return 1;
      } else {
        return 0;
      }
    } else {
      return -1;
    }
  }
}