Q:

By side, a triangle has 3 types, equilateral if it has three equal sides, isosceles if it has two

0

By side, a triangle has 3 types:

equilateral if it has three equal sides, isosceles if it has two

equal sides and scalene if it has no equal sides. Write a Java program named TriangleType

that reads from the user 3 integer values l, m and n that represent the 3 sides of triangle, and

then determines and prints the triangle type (equilateral, isosceles, scalene). You have to

apply the triangle inequality for with the three entered triangle sides, i.e. you have to assure

that each side in a triangle is less than the sum of other two sides and greater than the

difference between them

 

Sample Run 1:

Enter 3 sides of a triangle: 2 18 4

Not a Triangle

=====================================

Sample Run 2:

Enter 3 sides of a triangle: 7 8 4

Triangle type: Scalene

=====================================

Sample Run 3:

Enter 3 sides of a triangle: 6 8 6

Triangle type: Isosceles

=====================================

Sample Run 4:

Enter 3 sides of a triangle: 5 5 5

Triangle type: Equilateral

=====================================

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		System.out.println("Enter 3 sides of a Triangle:");
		Scanner input =new Scanner(System.in);
		int l, m, n;
		l= input.nextInt();
		m= input.nextInt();
		n= input.nextInt();
		if(l )
		{
		System.out.print("Triangle type: ");
		if (l==m==n)
		System.out.println("Equilateral");
		else if(l==m || m==n || l==n)
		System.out.println("isosceles");
		else if(l!=m && m!=n && l!=n)
		System.out.println("scalene");
		}
		else{
		    System.out.println("not a Triangle");
		}
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now