-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-39.java
More file actions
37 lines (34 loc) · 750 Bytes
/
problem-39.java
File metadata and controls
37 lines (34 loc) · 750 Bytes
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
public class Problem39 {
public static boolean isRightTrig(int a, int b, int c) {
if (a*a + b*b == c*c) {
return true;
}
else {
return false;
}
}
public static void main(String[] args) {
int maxSols = 0;
int maxPerim = 0;
for (int p = 1; p < 1000; p++) {
int currSols = 0;
for (int a = 1; a <= p/2; a++) {
for (int b = a; b <= p/2; b++) {
for (int c = b; c <= p/2; c++) {
if (a+b+c == p) {
if (isRightTrig(a,b,c)) {
currSols++;
}
}
}
}
}
if (currSols > maxSols) {
maxSols = currSols;
maxPerim = p;
}
}
System.out.println("The max number of solutions is: " + maxSols);
System.out.println("This corresponds to a perimeter of: " + maxPerim);
}
}