Created
November 21, 2017 10:45
-
-
Save ndczz/8a48253bb21d2f4fd47e42e69b930788 to your computer and use it in GitHub Desktop.
QuadroSolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuadraticSolver { | |
public static final int RESULT_BAD = 0; | |
public static final int RESULT_ONE = 1; | |
public static final int RESULT_TWO = 2; | |
public static final Result solve(double a, double b, double c) { | |
double d = b * b - 4 * a * c; | |
if (d < 0) | |
return new Result(RESULT_BAD, 0, 0); | |
double sqd = Math.sqrt(d); | |
double root1 = (-b + sqd) / (2 * a); | |
double root2 = (-b - sqd) / (2 * a); | |
return new Result(RESULT_TWO, root1, root2); | |
} | |
public static class Result { | |
public int status; | |
public double first; | |
public double second; | |
public Result(int status, double first, double second) { | |
this.status = status; | |
this.first = first; | |
this.second = second; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment