The program first prompts the user to enter three angles of a triangle using the Scanner class. Then it calculates the sum of the angles using the + operator and stores it in the variable sum.
The program then checks if the sum of the angles is equal to 180 and all angles are greater than zero using an if statement. If both conditions are true, then the program prints "Triangle is valid". Otherwise, it prints "Triangle is not valid".
Overall, this program provides a basic validation for checking if three angles could form a valid triangle or not. However, it is important to note that this validation does not guarantee that the sides of the triangle would be valid or not, as there are other conditions to be met in order for a triangle to be valid.
import java.util.Scanner; class Triangle_Valid { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter Three Angles of Triangle :"); int angle1 = input.nextInt(); int angle2 = input.nextInt(); int angle3 = input.nextInt(); int sum = angle1 + angle2 + angle3; if(sum == 180 && angle1 > 0 && angle2 > 0 && angle3 > 0) { System.out.println("Triangle is valid"); } else { System.out.println("Triangle is not valid"); } } }
Enter Three Angles of Triangle : 65 45 60 Triangle is not valid
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions