Computer Science, asked by arpityadav75647, 1 year ago

Write a program to input three side of a triangle and check whether the it is formed a triangle if it is formed triangle find which type of triangle is this in Java

Answers

Answered by sushiladevi4418
0

Answer:-

Java program to check the type of triangle.

Explanation:

public class TriangleT{

   static Triangle getType(int x, int y, int z)

   {

       if(x<=0||y<=0||z<=0)

           throw new IllegalArgumentException("Length cannot be equal to or less than zero");

       if(x==y&&y==z&&z==x)

           return Triangle.EQUILATERAL;

       else if((x==y)||(y==z||(z==x))

           return Triangle.ISOSCELES;

       else if(x!=y&&y!=z&&z!=x)

           return Triangle.SCALENE;

       else

           return Triangle.ERROR;

   }

   public static void main(String[] args)

   {

       System.out.println(TriangleT.getType(13, 13, 0));

   }

}

enum Triangle

{

ISOSCELES(0),

EQUILATERAL(1),

SCALENE(2),

ERROR(3);

private int p;

Triangle(int p)

{this.p = p;}

}

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