a) Write a program in Java to accept three angles of a triangle. Check whether the triangle is a
Acute-angled triangle, Right-angled triangle or Obtuse-angled triangle.
Answers
Answer:
Write a program to input three angles of a triangle and check whether a triangle is impossible or not . If possible then check whether it is an acute angled triangle , right angled triangle or an obtuse angled triangle otherwise, display 'Triangle not possible'. Sample input : Enter the angles: 40, 50 , 90.
Program :-
import java.util.Scanner; \\ importing package
class d \\ class declaration
{
public static void main (String args[]) \\ main()method declaration
{
Scanner sc= new Scanner(System.in); \\ input object creation
System.out.println("Enter three angles of a triangle");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int s = a+b+c;
if (s == 180 && a > 0 && b > 0 && c > 0)
{
if (a < 90 && b < 90 && c < 90)
{
System.out.println("Acute-angled Triangle");
}
else if (a == 90 || b == 90 || c == 90)
{
System.out.println("Right-angled Triangle");
}
else
{
System.out.println("Obtuse-angled Triangle");
}
}
else
{
System.out.println("Triangle cannot be formed");
}
}
}
Output :-
Enter three angles of a triangle
90
45
45
Right-angled Triangle
Glossary :-