Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,833 members, 7,810,203 topics. Date: Friday, 26 April 2024 at 11:37 PM

Better Way Of Writing This Java Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Better Way Of Writing This Java Code (1306 Views)

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)

(1) (Reply)

Better Way Of Writing This Java Code by ogzille(m): 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(m): 7:04pm On Nov 19, 2011
suggestions plssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss cry

(1) (Reply)

An Open Source Mathematics C++ Class That Solves Mathematical Problems On Set / PASCAL Program / I want to learn programming but hate mathematics

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.