Java Program to Find Type of Triangle from given Coordinates

bookmark

public class Main
{
   public static void main(String[] args)
   {
   int x1 = 0;
   int y1 = 0;
   int x2 = 10;
   int y2 = 8;
   int x3 = 1;
   int y3 = 5;
       // formula to find distance between 2 points
       double a = Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
       double b = Math.sqrt(Math.pow(x3-x2,2)+Math.pow(y3-y2,2));
       double c = Math.sqrt(Math.pow(x3-x1,2)+Math.pow(y3-y1,2));
       // side checking 
       if (a == b && b == c)
           System.out.println("Equilateral triangle");
       else if (a == b || b == c)
           System.out.println("Isosceles triangle");
       else
           System.out.println("Scalene triangle");
       // angle checking using Pythagoras theorem
       if (a + b > c)
           System.out.println("Acute angle triangle"); 
       else if (a + b == c)
           System.out.println("Right angle triangle");
       else
           System.out.println("Obtuse angle triangle"); 
   }
}

 


Output:

Scalene triangle
Acute angle triangle