pythagoras integer sides triangle

Absolute beginner needs tips!!

I need to make a program that gives me triangles with only integer numbers using a2+b2=c2.

Here's my code, it works but it gives me double results as you can see. How can I improve, just using code I already now? (loop statements, conditions etc..)

Thanks for any tips

// Ex. 5.21 Pythagorian triples

public class Pythagorian

{

public static void main( String args[] )

{

int a = 0;

int b = 0;

int c = 0;

for( a = 1 ; a <= 9 ; a++ )

{

for( b = 1 ; b <= 9 ; b++ )

{

for ( c = 1 ; c <= 100 ; c ++)

if ((c*c)==(a*a + b*b))

System.out.printf( "A is %d and B is%d and C is %d\n" , a , b, c);

} // end b

} // end a

} // end main

} // end class

[818 byte] By [desiguala] at [2007-10-2 21:04:45]
# 1
hey, this is an algorithm problem and not a java problem..... http://www.mathpath.uni.cc/Message was edited by: pat2kin
pat2kina at 2007-7-13 23:49:58 > top of Java-index,Java Essentials,New To Java...
# 2
I assume you are getting both:3 4 5and4 3 5Make your 'b' loop only process numbers that are equal or greater than 'a' ('equal' won't give you a Pythagorean triple, anyway, so you could probably skip it).
MLRona at 2007-7-13 23:49:58 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks for both answers, they both solved my doubts.
desiguala at 2007-7-13 23:49:58 > top of Java-index,Java Essentials,New To Java...