Updated for performance

This commit is contained in:
2020-06-15 20:07:01 -04:00
parent d570274fa9
commit 3b6e5e32ce

View File

@@ -29,10 +29,10 @@ public class Problem9 extends Problem{
} }
public void solve(){ public void solve(){
//Setup the variables //Setup the variables
Integer a = 1; //Holds the length of the first side int a = 1; //Holds the length of the first side
Integer b = 0; //Holds the length of the second side int b = 0; //Holds the length of the second side
Double c = 0D; //Holds the length of the hyp double c = 0D; //Holds the length of the hyp
Boolean found = false; //A flag to show whether the solution has been found boolean found = false; //A flag to show whether the solution has been found
//Start the timer //Start the timer
timer.start(); timer.start();
@@ -62,7 +62,7 @@ public class Problem9 extends Problem{
//Save the results //Save the results
if(found){ if(found){
result = String.format("The Pythagorean triplet is %d + %d + %d\nThe numbers' product is %d\n", a, b, c.intValue(), a * b * c.intValue()); result = String.format("The Pythagorean triplet is %d + %d + %d\nThe numbers' product is %d\n", a, b, Math.round(c), a * b * Math.round(c));
} }
else{ else{
result = "The number was not found!"; result = "The number was not found!";
@@ -73,5 +73,5 @@ public class Problem9 extends Problem{
/* Results: /* Results:
The Pythagorean triplet is 200 + 375 + 425 The Pythagorean triplet is 200 + 375 + 425
The numbers' product is 31875000 The numbers' product is 31875000
It took 12.971 milliseconds to solve this problem. It took 139.599 microseconds to solve this problem.
*/ */