Question: So I need help calculating Pythagorean Triples, basically I want the output to look like this:

```
3 4 5
5 12 13
6 8 10
7 24 25

```

ETC.

I need help with the calculation portion and to ensure that I do not have duplicates (i.e. 5 12 13 and 12 5 13).

Thoughts? Can someone lead me in the right direction?

Here is my code that I have so far:

```
package cs520.hw1;

public class Triples {

        public static void main(String[] args) 
        {
            int x1, x2, x3; 

            for(x1 = 1; x1 < 100; x1++)
            {
                for(x2 = 1; x2 < 100; x2++)
                {
                    for(x3 = 1; x3 < 100; x3++)
                    {
                        int a= x1, b=x2, c=x3;

                        if((Math.sqrt(a) + Math.sqrt(b)) == Math.sqrt(c))
                        {
                            if(a < b)
                            {
                                System.out.println(x1 +"  "+ x2 +"   "+ x3);
                            }
                        }
                    }
                }
            }       
        }
    }

```

Answer: 
**Example code:**

```
public class QuickTester {

    // Change MAX to whatever value required
    private static final int MAX = 25;

    public static void main(String[] args) {

        int a, b, c;

        for(a = 1; a < MAX; a++)
        {
            for(b = a; b < MAX; b++)
            {
                for(c = b; c < MAX; c++)
                {
                    if((Math.pow(a, 2) + Math.pow(b, 2))
                            == Math.pow(c, 2))
                    {
                        System.out.printf("%d %d %d\n",
                                a, b, c);
                    }
                }
            }
        }
    }
}

```

**Output (for MAX being 25 instead of 100):**

```
3 4 5
5 12 13
6 8 10
8 15 17
9 12 15
12 16 20

```

**Note:**

* To ensure that you don't get (5 12 13 and 12 5 13), simply make sure that a < b < c.
* Use (Math.pow(a, 2) + Math.pow(b, 2)) == Math.pow(c, 2) to find the triplets
You need to change the calls to `Math.sqrt(n)` to `Math.pow(n, 2)`, where n = a, b, c.

So, the code becomes

```
 package cs520.hw1;

 public class Triples {

 public static void main(String[] args) 
 {
        int x1, x2, x3; 

        for(x1 = 1; x1 < 100; x1++)
        {
            for(x2 = 1; x2 < 100; x2++)
            {
                for(x3 = 1; x3 < 100; x3++)
                {
                    int a= x1, b=x2, c=x3;

                    if((Math.pow(a, 2) + Math.pow(b, 2)) == Math.pow(c, 2))
                    {
                        if(a < b)
                        {
                            System.out.println(x1 +"  "+ x2 +"   "+ x3);
                        }
                    }
                }
            }
        }       
    }
}

```