Java Reference
In-Depth Information
// if discr > 0 equation has 2 real roots
// if discr == 0 equation has a repeated real root
// if discr < 0 equation has imaginary roots
// if discr is NaN equation has no roots
// Test for NaN
if(Double.isNaN(discr))
System.out.println(“Equation has no roots”);
if(discr > 0)
{
System.out.println(“Equation has 2 roots”);
root1 = (-b + discr)/2 * a;
root2 = (-b - discr)/2 * a;
System.out.println(“First root=”+root1);
System.out.println(“Second roor=”+root2);
}
if(discr == 0)
{
System.out.println(“Equation has 1 root”);
root1 = (-b + discr)/2 * a;
System.out.println(“Root=”+root1);
}
if(discr < 0)
System.out.println(“Equation has imaginary roots”);
}
}
On the Web
The program QuadSolv.java can be found in the Chapter 24 folder at
www.crcpress.com .
Search WWH ::




Custom Search