-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ5.java
More file actions
46 lines (37 loc) · 1.18 KB
/
Q5.java
File metadata and controls
46 lines (37 loc) · 1.18 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class Q5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter three sides of a triangle:");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a + b > c && b + c > a && c + a > b) {
System.out.println("It forms a triangle");
int max = Math.max(a, Math.max(b, c));
int x, y;
if (max == a) {
x = b;
y = c;
} else if (max == b) {
x = a;
y = c;
} else {
x = a;
y = b;
}
int lhs = x * x + y * y;
int rhs = max * max;
if (lhs == rhs) {
System.out.println("It is a right-angled triangle");
} else if (lhs > rhs) {
System.out.println("It is an acute-angled triangle");
} else {
System.out.println("It is an obtuse-angled triangle");
}
} else {
System.out.println("It does not form a triangle");
}
sc.close();
}
}