Programming Examples
Java program to input the three sides of a triangle and check whether it equilateral isosceles or a scalene triangle
![](https://programmingtrick.com/upload/1659413946.jpg)
Write a program to input the three sides of a triangle and check whether it forms a triangle or not, if it forms a triangle, check whether it is an equilateral, isosceles or a scalene triangle.
(Hint: To form a triangle, each side should be less the sum of the other two sides.
To form an equilateral triangle every side should be equal.
To form an isosceles triangle any two sides should be equal.
To form a scalene triangle all three sides should be different from each other.)
Solution
import java.util.*;
class Triangle
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
int a,b,c;
System.out.println(“Enter 3 sides:”);
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if(a<b+c && b<a+c && 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(“Cannot form a triangle”);
}
}
Output