₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,183 members, 8,510,574 topics. Date: Friday, 30 October 2026 at 04:13 PM

Toggle theme

Better Way Of Writing This Java Code - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Better Way Of Writing This Java Code (1427 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 Code • Step-by-step Method Of Writing Contiki Programs • Improve The Speed Of This Java Code. • 2 • 3 • 4

A Nairalander's First Invention In Nigeria • Help!! I Need A Laptop To Run My Code!!! • Linux Or Unix