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

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -