Is being a right triangle both necessary and sufficient for the Pythagorean Theorem to hold? I recently encountered a Stack Overflow question (since closed) in which the OP was testing for whether a triangle was right by whether or not it "met" the criteria of the Pythagorean Theorem (i.e. whether or not the square of the hypotenuse is equal to the square of the two sides). The code was to this effect:
public void Test(int a, int b, int c) {
   if ((c * c) == ((a * a) + (b * b)) {
     System.out.println("This is a right triangle");
   }
   else {
     System.out.println("This is not a right triangle");
   }
}

(There are obviously some other problems with this code, like the fact that it doesn't validate the input to make sure that the inputs are positive and the fact that it only accepts integers).
The question was asking about something completely different in the code and never directly addressed the test, but I got to thinking: is this a valid test for whether a triangle is a right triangle?
Obviously, the Pythagorean Theorem states that, for all right triangles, $a^2 + b^2 = c^2$ (where $a$ and $b$ are sides and $c$ is the hypotenuse). This will hold for all right triangles, so being a right triangle is a sufficient condition for the Pythagorean Theorem to hold.
Is it also a necessary condition? I.e. if $c^2 = a^2 + b^2$ for some arbitrary triangle, is the triangle necessarily a right triangle? Or are there counterexamples?
 A: Suppose that $a^2 + b^2 = c^2$ is a necessary condition to be a right triangle.
Corollary: $a^2 + b^2 = c^2$ is a sufficient condition to be a right triangle.
Proof: Suppose you're given a particular triangle whose side lengths satisfy $a^2 + b^2 = c^2$.
Construct a right triangle whose two sides adjacent to the angle are of length $a$ and $b$ (e.g. start with the right angle, and mark off the two sides to have the appropriate length). By the supposition, it follows that the third side of the right triangle has length $c$.
By the side-side-side congruence theorem, the original triangle is congruent to the right triangle, and thus the original triangle is a right triangle.
A: Yep, the converse of the Pythagorean Theorem is also true. It can be proved using the law of cosines:
Assume $a,b,c$ are the sides of a triangle and they satisfy $a^2 + b^2 = c^2$. Let $\angle ACB = \gamma$. By the law of cosines,
$$ c^2 = a^2 + b^2 - 2ab\cos\gamma . $$
Since $a,b > 0$, we must have $\cos\gamma = 0$. Since $0 < \gamma < 180^\circ$, we must have $\gamma = 90^\circ$. So $\Delta ABC$ is a right triangle. 
A: The law of cosines states that 
$$
c^2=a^2+b^2-2ab\cos(C),
$$
where $C$ is the angle opposite the side of length $c$. When does $\cos(C)=0$?
A: Let $ABC$ be a non-degenerate triangle with side lengths fulfilling $BC^2+AC^2=AB^2$.
Let $\ell$ be the line perpendicular to $BC$ and going through $C$. 
Let $A'$ and $A''$ be the two distinct points where the circle around $C$ of radius $AC$ intersects $\ell$.
Then $A'BC$ and $A''BC$ are right triangles.
By Pythagoras, $A'B^2=BC^2+A'C^2=BC^2+AC^2=AB^2$ and likewise $A''B^2=AB^2$.
This means that the circle around $B$ of radius $AB$ and the circle around $C$ of radius $AC$ intersect in $A$, $A'$, and $A''$.
As there are in fact only two points of intersection and as certainly $A'\ne A''$, we conclude that $A=A'$ or $A=A''$. In both cases, $ABC$ is a right triangle.
A: Yes, and this goes back to Euclid.   Euclid I.47 is "In right-angled triangles the square on the side opposite the right angle equals the sum of the squares on the sides containing the right angle."  Euclid I.48 is the converse, "If in a triangle the square on one of the sides equals the sum of the squares on the remaining two sides of the triangle, then the angle contained by the remaining two sides of the triangle is right."
A: The Pythagorean theorem gives a necessary and sufficient characterization of being a right triangle. In other words, when $a$, $b$, and $c$ are the side lengths of a triangle, $a^2 + b^2 = c^2$ is equivalent to the angle opposite the $c$-side being a right angle. This follows from the law of cosines, which states
$$ c^2 = a^2 + b^2 - 2 ab \cos C $$
where $C$ is the angle opposite the $c$-side, for any triangle with side lengths $a$, $b$, and $c$. We only get $c^2 = a^2 + b^2$ when $\cos C = 0$, or when $C = 90^{\circ}$.
It is also interesting to note that this theorem (both the necessary and sufficient parts) are proved in Euclid's Elements via geometric methods.
A: As other answers have pointed out, this is indeed correct. Although you could nitpick that it isn't correct outside of Euclidean geometry. That is, you could have "right triangles" on a sphere or other non-planar surfaces where the Pythagorean theorem wouldn't hold, and some non-right triangles where it does.
I wonder whether it would still hold true in non-Euclidean geometry if you additionally impose the sum of angles to be 180 degrees.
