Programming Examples
Java program to input the three angles of a triangle and check whether it equilateral isosceles or a scalene triangle
Write a program to input the three angles 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, the sum of the angles should be 180 degrees.
To form an equilateral triangle every angle should be equal.
To form an isosceles triangle any two angles should be equal.
To form a scalene triangle all three angles 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 angles:”);
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if(a+b+c==180)
{
if(a<90 && b<90 && c<90)
System.out.println(“Acute angled triangle”);
else if(a>90 || b>90 || c>90)
System.out.println(“Obtuse angled triangle”);
else
System.out.println(“Right angled triangle”);
}
else
System.out.println(“Cannot form a triangle”);
}
}
Output