Java Programming : check whether the triangle is valid in terms of angles

Example

Input
30 60 90
Output
Triangle is valid

Required to Know

Use of Variables, Use of different operators like assignment or arithmetic operators, Use of methods like System. out. print(), and use of if else, and Use of Data types

Steps

This program determines the type of triangle based on the angles. Here's a breakdown of how it works:

  • The program imports the Scanner class from the java.util package.

  • It defines a class called Mavenproject1.

  • The Mavenproject1 class has a static method called main that takes an array of strings as input.

  • Within the main method, the program creates a Scanner object to read input from the user.

  • The program prompts the user to enter three integer values that represent the angles of a triangle.

  • The program checks if the sum of the angles is equal to 180 and if all three angles are greater than zero.

  • If the conditions are met, the program prints "Triangle is valid".

  • Otherwise, the program prints "Triangle is not valid".

Program

import java.util.Scanner; 
public class Mavenproject1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); 
        int angle1,angle2, angle3;
        angle1 = sc.nextInt(); 
        angle2 = sc.nextInt(); 
        angle3 = sc.nextInt(); 
        int sum = angle1+angle2+angle3; 
        if(sum==180 && angle1>0 && angle2>0 && angle3>0){
            System.out.print("Triangle is valid");
        }
        else{
            System.out.print("Triangle is not valid"); 
        }

    }
}