Computer Science, asked by Atlas99, 5 hours ago

Java Programming
________________
Find different types of triangles using if else if.
You can take different types of triangles as Equilateral, scalene and isosceles.​

Answers

Answered by anindyaadhikari13
17

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

import java.util.Scanner;

public class Triangle{

   public static void main(String args[]){

       Scanner sc=new Scanner(System.in);

       double a,b,c;

       System.out.print("Enter first side of triangle: ");

       a=sc.nextDouble();

       System.out.print("Enter second side of triangle: ");

       b=sc.nextDouble();

       System.out.print("Enter third side of triangle: ");

       c=sc.nextDouble();

       sc.close();

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

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

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

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

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

           else

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

       }

       else

           System.out.println("Triangle Not Possible.");

   }

}

\textsf{\large{\underline{Logic}:}}

  1. At first, check whether the triangle is possible or not. A triangle is possible when sum of two sides is greater than the other side.
  2. Now, check if all the sides of triangle are equal or not. If true, triangle is Equilateral.
  3. If false, check if any two sides are equal or not. If true, the triangle is Isosceles.
  4. If all the conditions are false, the given triangle is Scalene.

See the attachments for output.

Attachments:

anindyaadhikari13: Thanks for the Brainliest :)
Answered by Itzintellectual
0

Explanation:

\textsf{\large{\underline{Solution}:}}

Solution

:

The given problem is solved using language - Java.

import java.util.Scanner;

public class Triangle{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

double a,b,c;

System.out.print("Enter first side of triangle: ");

a=sc.nextDouble();

System.out.print("Enter second side of triangle: ");

b=sc.nextDouble();

System.out.print("Enter third side of triangle: ");

c=sc.nextDouble();

sc.close();

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

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

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

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

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

else

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

}

else

System.out.println("Triangle Not Possible.");

}

}

\textsf{\large{\underline{Logic}:}}

Logic

:

At first, check whether the triangle is possible or not. A triangle is possible when sum of two sides is greater than the other side.

Now, check if all the sides of triangle are equal or not. If true, triangle is Equilateral.

If false, check if any two sides are equal or not. If true, the triangle is Isosceles.

If all the conditions are false, the given triangle is Scalene.

See the attachments for output.

Similar questions