Formula to calculate quadratic - Android java.lang

Android examples for java.lang:Math Formula

Description

Formula to calculate quadratic

Demo Code


import java.text.DecimalFormat;

public class Main{
    private static double[] results = new double[2];
    public static double[] quadratic(double a, double b, double c)
            throws InvalidInputException {
        if (((b * b - (4 * a * c)) < 0) == false) {
            results[0] = (-b + (Math.sqrt(b * b - (4 * a * c)))) / (2 * a);
            results[1] = (-b - (Math.sqrt(b * b - (4 * a * c)))) / (2 * a);
            return results;
        } else {//  ww w  .j a  v a  2 s . com
            throw new InvalidInputException();
        }
    }
}

Related Tutorials