Computer Science, asked by vijay1555, 9 months ago

write a java program to find the type of triangle given​

Answers

Answered by gurmukhsingh1192
2

Answer:

We are given coordinates of a triangle. The task is to classify this triangle on the basis of sides and angle.

Examples:

Input: p1 = (3, 0), p2 = (0, 4), p3 = (4, 7) Output: Right Angle triangle and Isosceles Input: p1 = (0, 0), p2 = (1, 1), p3 = (1, 2); Output: Triangle is obtuse and Scalene

Recommended: Please try your approach on {IDE}first, before moving on to the solution.

Approach:

We can solve this problem by first calculating the side length and then classifying on comparing of side lengths. Classification by sides is simple, if all sides are equal, triangle will be equilateral, if any two sides are equal triangle will be Isoscelesotherwise it will be Scalene.

Now angle can be classified by Pythagoras theorem, if sum of square of two sides is equal to square of the third side, triangle will be right angle, if less triangle will be acute angle else it will be obtuse angle triangle.

Below is written simple code for classification of triangle:

C++

// C/C++ program to classify a given triangle

  

#include <bits/stdc++.h>

using namespace std;

  

struct point {

    int x, y;

    point() {}

    point(int x, int y)

        : x(x), y(y)

    {

    }

};

  

// Utility method to return square of x

int square(int x)

{

    return x * x;

}

  

// Utility method to sort a, b, c; after this

// method a <= b <= c

void order(int& a, int& b, int& c)

{

    int copy[3];

    copy[0] = a;

    copy[1] = b;

    copy[2] = c;

    sort(copy, copy + 3);

    a = copy[0];

    b = copy[1];

    c = copy[2];

}

  

// Utility method to return Square of distance

// between two points

int euclidDistSquare(point p1, point p2)

{

    return square(p1.x - p2.x) + square(p1.y - p2.y);

}

  

// Method to classify side

string getSideClassification(int a, int b, int c)

{

    // if all sides are equal

    if (a == b && b == c)

        return

Answered by mithulpranav24826
0

This program finds out the type of triangle by using the values of the sides.

To get the answer, run the program and enter the values of the sides when you are asked to. Once you enter all the values you will get the final answer.

Answer:

import java.io.*;

class triangle

{

   public static void main (String [] args) throws IOException

   {

       InputStreamReader isr=new InputStreamReader(System.in);

       BufferedReader abc= new BufferedReader(isr);

       System.out.println("Enter the First Side");

       int a=Integer.parseInt(abc.readLine());

       System.out.println("Enter the Second Side");

       int b=Integer.parseInt(abc.readLine());

       System.out.println("Enter the Third Side");

       int c=Integer.parseInt(abc.readLine());

       if (a==b && a==c && b==c)

       {

           System.out.println("Equilateral Triangle");

       }

       else if (a==b || b==c || c==a  )

       {

           System.out.println("Isosceles Triangle");

       }

       else if (a!=b && b!=c && c!=a)

       {

           System.out.println("Scalene Triangle");

       }

   }

}

Answered by M.Mithul Pranav.

Hope it helps.

Similar questions