public class pythagorean
{
public static void main(String[] args)
{
int a, b, c;
for (a = 1; a <= 500; a++)
{
for (b = 1; a <= 500; b++)
{
for (c = 1; c <= 500; c++)
{
if (Math.pow(a,2) + Math.pow(b,2) == Math.pow(c,2))
{
System.out.printf("%d %d %d\n", a, b, c);
}
}
}
}
}
}
For some reason, nothing appears on the output window:
cmd.jpg 32.91K
67 downloadsEDIT: Ok, I edited the program a little bit. Instead of using Math.pow(), I just multiplied the variables to themselves. Here's the code:
public class pythagorean
{
public static void main(String[] args)
{
int a, b, c;
for (a = 1; a <= 500; a++)
{
for (b = 1; a <= 500; b++)
{
for (c = 1; c <= 500; c++)
{
if ((a * a) + (b * b) == (c * c))
{
System.out.println(a + " " + b + " " + c);
}
}
}
}
}
}
And now this happened:
cmd2.jpg 65.02K
90 downloadsEDIT 2: Oooh, now I saw the error. I mistyped the second for loop condition. Forget the whole thing, I got it now. Sorry about wasting your time. :P


Sign In
Create Account

This topic is locked

Back to top










