write a program in Java language to enter the three angles of a triangle and check for the validity of the triangle....plz answer the question
Answers
CODE
import java.util.*;
class triangle_validity
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the three angles of triangle");
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a+b+c==180&&a!=0&&b!=0&&c!=0)
{
System.out.println("Triangle valid");
}
else
{
System.out.println("Triangle invalid");
}
}
}//the End
NOTE :
Triangle property is that all angles are added to get 180 degrees . Any angle cannot be 0 degrees .
OUTPUT in attachment .
Hey there!
The coding is as follows:
import java.io.*;
class Validity_of_triangle //Declaration of class
{
public static void main(String args[]) throws IOException
{
//Making Input Stream Reader object
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(ir);
System.out.println("Enter the three angles of triangle");
int a=Integer.parseInt(br.readLine());
int b=Integer.parseInt(br.readLine());
int c=Integer.parseInt(br.readLine());
// using AND logical operator
if(a+b+c==180&&a!=0&&b!=0&&c!=0)
{
System.out.println("Triangle is valid");
}
else
{
System.out.println("Triangle is invalid");
}
}
} //End of the program
Note: Please have a look at attachments for Better Understanding.
Hope it Helps You!