Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,081 members, 7,957,045 topics. Date: Tuesday, 24 September 2024 at 05:46 AM |
Nairaland Forum / Science/Technology / Programming / Better Way Of Writing This Java Code (1339 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" 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 |
(1) (Reply)
Difference Between Developer And Programmer. Interview Question / I want to learn programming but hate mathematics / To Programmers Looking For JOBS And CHALLENGES
(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. 7 |