Java - Statement Valid Triangle

Description

Valid Triangle

Demo

import java.util.Scanner;

public class ValidTriangle {
  public static boolean isValid(int one, int two, int three) {
    boolean valid = true;

    if (one + two + three != 180) {
      valid = false;// w w w. ja  v  a2 s . c om
    }
    return valid;
  }

  public static boolean isEquilateral(int one, int two, int three) {
    boolean equilateral = false;

    if (one == two && two == three) {
      equilateral = true;
    }
    return equilateral;
  }

  public static boolean isRight(int one, int two, int three) {
    boolean right = false;

    if (one == 90 || two == 90 || three == 90) {
      right = true;
    }
    return right;
  }

  public static boolean isIsosceles(int one, int two, int three) {
    boolean isosceles = false;

    if (one == two || two == three || one == three) {
      isosceles = true;
    }
    return isosceles;
  }

  public static boolean isObtuse(int one, int two, int three) {
    boolean obtuse = false;

    if (one > 90 || two > 90 || three > 90) {
      obtuse = true;
    }
    return obtuse;
  }

  public static void main(String args[]) {
    int side1 = 60;
    int side2 = 60;
    int side3 = 60;

    boolean valid = isValid(side1, side2, side3);
    boolean equilateral = isEquilateral(side1, side2, side3);
    boolean isosceles = isIsosceles(side1, side2, side3);
    boolean right = isRight(side1, side2, side3);
    boolean obtuse = isObtuse(side1, side2, side3);

    if (valid == false) {
      System.out.println("The triangle is not valid");
    }

    else {
      System.out.println("The triangle is valid");

      if (equilateral) {
        System.out.println("The triangle is equilateral");
      }
      else {
        System.out.println("The triangle is not equilateral");
      }

      if (isosceles) {
        System.out.println("The triangle is isosceles");
      }
      else {
        System.out.println("The triangle is not isosceles");
      }

      if (right) {
        System.out.println("The triangle is right");
      }
      else {
        System.out.println("The triangle is not right");
      }

      if (obtuse) {
        System.out.println("The triangle is obtuse");
      }
      else {
        System.out.println("The triangle is not obtuse");
      }
    }
    scanner.close();
  }
}

Related Topic