(Pythagorean Triples) A right triangle can have sides whose lengths are all integers. A set of three integer values for the lengths of the sides of a right triangle is called a Pythagorean triple. The lengths of the three sides must must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse. Write an application to find all Pythagorean triples for side1, side2 and the hypotenuse all no larger than 500. Use a triple-nested for loop that tries all posibilities. This method is an example of “brute-force“ computing. You will learn in more advanced computer science courses that there are large numbers of interesting problems for which there is no known algorithmic approach other than using shear brute force.

Your test class should look a bit like this:

public class PythagoreanTriples {

public static final int LARGEST_SIDE = 500;
public static final int LARGEST_SQUARE = LARGEST_SIDE * LARGEST_SIDE;

public static void main(String[] args)
{
(new PythagoreanTriples()).listPythagoreanTriples();
}

public void listPythagoreanTriples()
{
System.out.printf("%s\n%8s%8s%8s\n",
"a^2 + b^2 = c^2 for the following:",
"a", "b", "c");

// Loop - for every possible value of the shortest side...
// Loop - for every possible value of the middle length side...
// Loop - for every possible value of the hypotenuse...
// If the shortest side, middle side, and hypotenuse
// constitute a Pythagorean triple, print their values.
}
}

By following the comments is the above code, you should be able to get the PythagoreanTriples class to work. The solution will be available here at the end of next week’s class.