mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-07 09:23:57 -05:00
Updated for performance
This commit is contained in:
@@ -29,10 +29,10 @@ public class Problem9 extends Problem{
|
||||
}
|
||||
public void solve(){
|
||||
//Setup the variables
|
||||
Integer a = 1; //Holds the length of the first side
|
||||
Integer b = 0; //Holds the length of the second side
|
||||
Double c = 0D; //Holds the length of the hyp
|
||||
Boolean found = false; //A flag to show whether the solution has been found
|
||||
int a = 1; //Holds the length of the first side
|
||||
int b = 0; //Holds the length of the second side
|
||||
double c = 0D; //Holds the length of the hyp
|
||||
boolean found = false; //A flag to show whether the solution has been found
|
||||
|
||||
//Start the timer
|
||||
timer.start();
|
||||
@@ -62,7 +62,7 @@ public class Problem9 extends Problem{
|
||||
|
||||
//Save the results
|
||||
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{
|
||||
result = "The number was not found!";
|
||||
@@ -73,5 +73,5 @@ public class Problem9 extends Problem{
|
||||
/* Results:
|
||||
The Pythagorean triplet is 200 + 375 + 425
|
||||
The numbers' product is 31875000
|
||||
It took 12.971 milliseconds to solve this problem.
|
||||
It took 139.599 microseconds to solve this problem.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user