public String toString() {
        String formula = "";
        for (int exponent = coeffs.length-1; exponent >= 0; exponent--) {
            if (coeffs[exponent] != 0.0) {
                if (Math.abs(coeffs[exponent]) != 1.0 || exponent == 0)
                    formula += Math.abs(coeffs[exponent]);
                if (exponent == 1)
                    formula += "x";
                if (exponent > 1)
                    formula += "x^" + exponent;
            }
            if (exponent > 0) {
                if (coeffs[exponent-1] < 0)
                    formula += " - ";
                else if (coeffs[exponent-1] > 0)
                    formula += " + ";
            }
        }
        return formula;
    }