Pythagorean triple calculation in java -
i found way calculate pythagorean triple until number,but program duplicates , in different order . how can avoid this? try organize pythagorean triple c value (aa+bb=c*c) code
import java.util.scanner; public class ex4 { public static void main(string[] args) { scanner s = new scanner(system.in); int number; number = s.nextint(); for(int c=1;c<number;c++){ for(int b=1;b<number;b++){ for(int a=1;a<number-2;a++){ if(a*a + b*b == c*c) system.out.println("("+a+","+b+","+c+") : "+a+"*"+a+" + "+b+"*"+b+" = "+c+"*"+c); } } } } }
make change:
for(int c=1;c<number;c++){ for(int b=1;b<c;b++){ for(int a=1;a<b;a++){ if(a*a + b*b == c*c )
but aware more efficient methods such euclid's formula
Comments
Post a Comment