Better Way Of Writing This Java Code - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Better 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" ;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 |
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
What Is The Relationship Between Processor And I/o Device • What Are The Candidate Keys? • Help On SQL!!!
;