-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriangleOrNot.java
33 lines (29 loc) · 1.14 KB
/
TriangleOrNot.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class TriangleOrNot {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the degree for Angle A: ");
int A = input.nextInt();
System.out.println("Enter the degree for Angle B: ");
int B = input.nextInt();
System.out.println("Enter the degree for Angle C: ");
int C = input.nextInt();
// Check if the sum of angles is 180
if (A + B + C != 180 || A <= 0 || B <= 0 || C <= 0) {
System.out.println("Not a triangle");
} else {
// Check if it is a triangle using the angle sum property
if (A + B > C && A + C > B && B + C > A) {
// Check for equilateral triangle
if (A == B && B == C) {
System.out.println("It is an Equilateral Triangle");
} else {
System.out.println("It is a Triangle");
}
} else {
System.out.println("Not a triangle");
}
}
input.close(); // Close the scanner
}
}