-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathProblem_9.java
More file actions
28 lines (22 loc) · 469 Bytes
/
Problem_9.java
File metadata and controls
28 lines (22 loc) · 469 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
/*
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
*/
class Problem_9 {
public static void main(String[] args) {
for(int a = 3; a <= 1000; a++)
{
for(int b = a + 1; b <= 1000; b++)
{
double cSquare = Math.pow(a,2) + Math.pow(b,2);
double c = Math.pow(cSquare,0.5);
if(a + b + c == 1000)
{
double prod = a*b*c;
System.out.println((int)prod);
break;
}
}
}
}
}