₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,622 members, 8,446,316 topics. Date: Thursday, 16 July 2026 at 11:42 AM

Toggle theme

Better Way Of Writing This Java Code - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingBetter Way Of Writing This Java Code (1406 Views)

1 Reply

Better Way Of Writing This Java Code by ogzille(op): 8:28pm On Nov 18, 2011
I have this small code here, that is meant to check all the Pythagorean matches, with sides not exceeding 500.

Now the code i have here seems very very very clumsy. I believe there is a better way out of this clumsy solution. Kindly suggest better ways of doing this.


public class CheckHypotenuse
{
public static void main (String[] args)
{
int check =0;
System.out.printf("%20s%20s%20s", "Base", "Height", "Hypotenuse"wink;
for (int i=500; i > 0; i--)
{
for (int j=500; j > 0; j--)
{
for (int k=500; k > 0; k--)
{
double x = Math.sqrt (Math.pow(j,2) + Math.pow(k,2));
double cast = (double) i;
if ( x == cast)
{
System.out.printf("%20d%20d%20d\n", k, j, i);
check = 1;
break;
}
}
if (check == 1)
break;
}
check =0;
}
}
}
Re: Better Way Of Writing This Java Code by ogzille(op): 7:04pm On Nov 19, 2011
suggestions plssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss cry
1 Reply

Please I Need Help Writing This CodeStep-by-step Method Of Writing Contiki ProgramsImprove The Speed Of This Java Code.234

What Is The Relationship Between Processor And I/o DeviceWhat Are The Candidate Keys?Help On SQL!!!