You have given the three sides of the triangle, now you have to identify whether the given triangle is an equilateral or isosceles, or scalene triangle. And We have to write the java program to identify the triangle.
Triangle
Equilateral Triangle: Equilateral triangle is a triangle in which all sides are equal. As a triangle has three sides so if all the sides X, Y, and Z are equal i.e X = Y = Z. Then we can say the triangle is Equilateral.
Isosceles Triangle: Isosceles triangle is a triangle in which any two sides are equal. Suppose for a triangle with sides X, Y, and Z Can be said the Isosceles triangle is either X = Y or X = Z or Y = Z.
Scalene Triangle: Scalene triangle is a Triangle in which all sides are different or can say not equal.
Check a triangle is equilateral, isosceles or scalene triangle in Java
import java.util.*;
public class Main
{
public static void main (String[]args)
{
int x, y, z;
Scanner sc = new Scanner(System.in);
System.out.println("check triangle is equilateral, isosceles or scalene");
System.out.println("Please enter the X value: ");
x = sc.nextInt();
System.out.println("Please enter the Y value: ");
y = sc.nextInt();
System.out.println("Please enter the Z value: ");
z = sc.nextInt();
if (x == y && y == z )
System.out.println("Equilateral Triangle");
else if (x == y || y == z || z == x )
System.out.println("Isosceles Triangle");
else
System.out.println("Scalene Triangle");
}
}
Output 1:
check triangle is equilateral, isosceles or scalene
Please enter the X value:
4
Please enter the Y value:
4
Please enter the Z value:
7
Isosceles Triangle
Output 2:
check triangle is equilateral, isosceles or scalene
Please enter the X value:
4
Please enter the Y value:
4
Please enter the Z value:
4
Equilateral Triangle
Output 3:
check triangle is equilateral, isosceles or scalene
Please enter the X value:
1
Please enter the Y value:
2
Please enter the Z value:
3
Scalene Triangle