java program to input the three sides of a triangle and check whether it equilateral isosceles or a scalene triangle

Programming Example

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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad