Results 1 to 3 of 3
Thread: problem !!!
 01292010, 10:16 PM #1Member
 Join Date
 Jan 2010
 Posts
 61
 Rep Power
 0
problem !!!
i want to solve this problem
A Pythagorean triplet is a set of three natural numbers, a b c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
my code
public class Euler {
public static void main(String[] args) {
int i = 0;
int j = 1;
int k = 2;
while (Math.pow(i, 2) + Math.pow(j, 2) != Math.pow(k, 2) && i * j * k != 1000) {
i = j;
j = k;
++k;
}
System.out.println(i*j*k);
}
}
the out always 60 although && i * j * k == 1000 in while loop:eek:
i need helpLast edited by jperson; 01292010 at 11:04 PM.
 01292010, 10:59 PM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,614
 Rep Power
 12
The question isn't very clear. You say at the start you want pythagorean triples whose sum is 1000. But then in the code you check the product of the triples.
Since the first time the while loop condition is checked i*j*k=0*1*2=0, the loop condition is false and the loop body will never execute. Consequently what is output at the end of main() is zero not 60 as you state.
 01292010, 11:07 PM #3Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,614
 Rep Power
 12
Similar Threads

simple line problem / for loop problem
By helpisontheway in forum New To JavaReplies: 1Last Post: 11172009, 07:12 AM
Bookmarks