A triangle is valid if the sum of all the three angles is equal to 180 degrees. Write a Java program that asks the user to enter three integers as angles in degrees and check whether a triangle is valid or not. Write output with proper statements. (Use these values -Angle1 = 350, Angle2 = 450, Angle3 = 100)
Answers
Answer:
Angle3 = 100
Explanation:
Program :
import java.util.*;
public class MyClass {
public static void main(String args[])
{
Scanner Sc = new Scanner(System.in);
int a1 , a2 , a3;
System.out.print("Enter Angle 1 : ");
a1 = Sc.nextInt();
System.out.print("Enter Angle 2 : ");
a2 = Sc.nextInt();
System.out.print("Enter Angle 3 : ");
a3 = Sc.nextInt();
if(a1 + a2 + a3 == 180)
{
System.out.print("Triangle is valid. \nBecause the sum of angles is : "+(a1 + a2 + a3));
}
else
{
System.out.print("Triangle is not valid. \nBecause the sum of angles is : "+(a1 + a2 + a3));
}
}
}
Output :
Enter Angle 1 : 350
Enter Angle 2 : 450
Enter Angle 3 : 100
Triangle is not valid.
Because the sum of angles is : 900