I'm trying to solve exercise from Art & Science of Java, solution for quadratic equation.
import acm.program.*;
public class QuadraticEquation extends ConsoleProgram {
public void run(){
println("Enter coefficients for quadratic equation");
int a = readInt("Enter first number: ");
int b = readInt("Enter second number: ");
int c = readInt("Enter third number: ");
double result = quadratic(a,b,c);
println("The first solution is: " + result);
}
private double quadratic(int a, int b, int c){
double underSquare = (b*b-4*a*c);
double x = (-b+Math.sqrt(b*b-(4*a*c)))/(2*a);
if (underSquare < 0) {
return null;
} else {
return (x);
}
}
}
I have an error in line:
return null;
saying:
Type mismatch: cannot convert from null to double
I don't really understand what this error, how should I solve this correctly?