I'm a new java programmer and I'm trying to write a program that finds the roots of a quadratic equation by implementing the roots() method in this class.
I think I've figured out how to implement the equation, but the return statement says: Error-Type mismatch: cannot convert from double to Set
How would I fix this error?
Thank You!
package warmup;
import java.util.Set;
public class Quadratic {
/**
* Find the integer roots of a quadratic equation, ax^2 + bx + c = 0.
* @param a coefficient of x^2
* @param b coefficient of x
* @param c constant term. Requires that a, b, and c are not ALL zero.
* @return all integers x such that ax^2 + bx + c = 0.
*/
public static Set<Integer> roots(int a, int b, int c) {
//my code so far
double q = -b + (Math.sqrt(Math.pow(b, 2)-4*a*c)/2*a);
return q;
}
/**
* Main function of program.
* @param args command-line arguments
*/
public static void main(String[] args) {
System.out.println("For the equation x^2 - 4x + 3 = 0, the possible solutions are:");
Set<Integer> result = roots(1, -4, 3);
System.out.println(result);
}
}
Set<Integer>in the method's signature, but you return adouble.-b - ...and return both values at once. That really should be aSet<Double>though.double q&&return q!=Set<Integer>-bshould be divided by2aas well...