Java Program to check Triangle is Equilateral, Isosceles, or Scalene

Write a Java Program to check the triangle is Equilateral, Isosceles, or Scalene with an example. Any triangle is equilateral if all sides of the triangle are equal. If any of the two sides are equal, then Isosceles, otherwise, Scalene. This Java example allows entering triangle three sides. Next, we used else if to check whether all sides are equal or any two sides are equal. Based on the condition result, we print the Equilateral or Isosceles, and if all fails, then Scalene.

package Area;

import java.util.Scanner;

public class EquiIsoScalene1 {
	private static Scanner sc;

	public static void main(String[] args) {
		
		double side1, side2, side3;
		sc = new Scanner(System.in);	
		
		System.out.println("Please Enter Three sides of Triangle ");
		side1 = sc.nextDouble();
		side2 = sc.nextDouble();
		side3 = sc.nextDouble();
		
		if(side1 == side2 && side2 == side3) 
		{
			System.out.println("It is an Equilateral Triangle");
		}	
		else if(side1 == side2 || side2 == side3 || side1 == side3) 
		{
			System.out.println("It is an Isosceles Triangle");
		} 
		else 
		{
			System.out.println("It is a Scalene Triangle");
		}
	}
}
Java Program to check Triangle is Equilateral, Isosceles, or Scalene 1

Equilateral Triangle

Please Enter Three sides of Triangle 
60
60
60
It is an Equilateral Triangle

Scalene Triangle output

Please Enter Three sides of Triangle 
10
15
20
It is a Scalene Triangle

In this Java program, we declared the checkTriangle function that accepts the triangle sides and checks the triangle is Equilateral, Isosceles, or Scalene.

package Area;

import java.util.Scanner;

public class EquiIsoScalene2 {
	private static Scanner sc;

	public static void main(String[] args) {
		double side1, side2, side3;
		sc = new Scanner(System.in);
		
		System.out.println("Please Enter Three sides of Triangle ");
		side1 = sc.nextDouble();
		side2 = sc.nextDouble();
		side3 = sc.nextDouble();
		
		checkTriangle(side1, side2, side3);
	}
	
	public static void checkTriangle(double side1, double side2, double side3)
	{
		if(side1 == side2 && side2 == side3) {
			System.out.println("It is an Equilateral Triangle");
		}
		else if(side1 == side2 || side2 == side3 || side1 == side3) {
			System.out.println("It is an Isosceles Triangle");
		}
		else {
			System.out.println("It is a Scalene Triangle");
		}
	}
}
Please Enter Three sides of Triangle 
70
80
95
It is a Scalene Triangle