Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For some reason, this program compiles correctly, but it does not display the re

ID: 3637204 • Letter: F

Question

For some reason, this program compiles correctly, but it does not display the results. I do not know what is wrong.

Can someone help me? Thanks.

here is the code:
public class Triples
{
public static void main( String[] args)
{
int side1, side2, hypotenuse;

for ( side1=1; side1<=500; side1++);
for ( side2=1; side2<=500; side2++);
for (hypotenuse=1; hypotenuse<= 500; hypotenuse++);


//use the pythagorean theorem to print right triangles
if ( ( side1 * side1 ) + ( side2 * side2 ) ==
( hypotenuse * hypotenuse ) )
System.out.print( "s1: " +side1+ "side2:" +side2+ "hypotenuse:" +hypotenuse+"." );
}
}

Explanation / Answer

I've made some corrections to your code. It now works fine :)

public class Triples
{
public static void main( String[] args)
{
int side1, side2, hypotenuse;

for ( side1=1; side1<=500; side1++)
for ( side2=1; side2<=500; side2++)
for (hypotenuse=1; hypotenuse<= 500; hypotenuse++)
{
//use the pythagorean theorem to print right triangles
if ( ( side1 * side1 ) + ( side2 * side2 ) ==
( hypotenuse * hypotenuse ) )
System.out.print( "s1: " +side1+ "side2:" +side2+ "hypotenuse:" +hypotenuse+"." );

}
}
}