- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemNine.java
More file actions
Latest commit
26 lines (22 loc) · 624 Bytes
/
Copy pathProblemNine.java
File metadata and controls
26 lines (22 loc) · 624 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
/*A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
insights: http://en.wikipedia.org/wiki/Pythagorean_triple#Generating_a_triple
*/
publicclassProblemNine {
publicstaticvoidmain(String[] args) {
for (inti=1; i<=500; i++){
inta=i;
for (intj=a+1; j<=500; j++){
intb=j;
intc=1000-(a+b);
if (((a*a)+(b*b))==(c*c)){
intproduct=a*b*c;
System.out.println(a+" "+b+" "+c+" "+product);
}
}
}
}
}