Computer Science, asked by deepthidungala5, 2 months ago

John given task to his friend in order to check whether a triangle is valid or not if angles are given using if else.
**Property of a triangle : **
С.
a
b Б
a+b+c= 180°
Note: A triangle is said to be a valid triangle if and only if sum of angles is 180 deg.
Input Format
Take input as gregars as a engles
Constraints
NA
Output Format
Print string as a output​

Answers

Answered by dreamrob
0

Program :

import java.util.*;

class Triangle {

  public static void main(String args[])

  {

      Scanner Sc = new Scanner(System.in);

      int angle1 , angle2 , angle3;

      System.out.print("Enter Angle 1 : ");

      angle1 = Sc.nextInt();

      System.out.print("Enter Angle 2 : ");

      angle2 = Sc.nextInt();

      System.out.print("Enter Angle 3 : ");

      angle3 = Sc.nextInt();

      if(angle1 + angle2 + angle3 == 180)

      {

          System.out.print("Triangle is valid. \nBecause the sum of angles is : " + (angle1 + angle2 + angle3));

      }

      else

      {

          System.out.print("Triangle is not valid. \nBecause the sum of angles is " + (angle1 + angle2 + angle3) + " which is not equal to 180");

      }

  }

}

Output 1 :

Enter Angle 1 : 20

Enter Angle 2 : 20

Enter Angle 3 : 20

Triangle is not valid.

Because the sum of angles is 60 which is not equal to 180

Output 2 :

Enter Angle 1 : 60

Enter Angle 2 : 90

Enter Angle 3 : 30

Triangle is valid.

Because the sum of angles is : 180

Similar questions