Computer Science, asked by 12ankita9a, 7 months ago

5. 5
Write a program to enter three sides of a triangle and check whether
the triangle is possible or not. If possible, then display whether it is
an Equilateral, an Isosceles or a Scalene Triangle, otherwise display the
message 'Triangle is not possible'.​

Answers

Answered by raotd
3

Answer:

Input sides of a triangle from user. Store it in some variables say side1 , side2 and side3 . Check if(side1 == side2 && side2 == side3) , then the triangle is equilateral. If it is not an equilateral triangle then it may be isosceles.

Explanation:

Answered by ayushdasgupta
19

Answer:

import java.util.*;

public class Triangle

{

     public static void main(String args[])

     {

             Scanner in=new Scanner(System.in);

             System.out.println("Enter the three sides of the triangle");

             int a=in.nextInt();

             int b=in.nextInt();

             int c=in.nextInt();

             if (a+b>c)&&(b+c>a)&&(c+a>b)

             {

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

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

                   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");

              }

              else

              {

              System.out.println("Triangle not possible");

              }

        }

}

             

               

Explanation:

First we have to enter the three sides of the triangle and then initialize it, then comes the decision checking part where we have to check whether triangle is possible or not possible according to the given condition. If triangle is possible then we have to check whether it is an equilateral triangle, isosceles triangle or scalene triangle

Similar questions