bob bob
2011-02-17 06:12:12 UTC
import java.io.*;
import java.util.*;
public class QuadraticFormula
{
public static void main(String[] args)
{
System.out.println("The form must be ax^2+bx+c to use this program.");
Scanner kbReader=new Scanner(System.in);
System.out.print("Enter A: ");//ax^2
double a= kbReader.nextDouble();
System.out.print("Enter B: ");//bx
double b= kbReader.nextDouble();
System.out.print("Enter C: ");// c
double c= kbReader.nextDouble();
double ab= 2;//number for the second power
double d= Math.pow( (double) b, (double) ab);//raises b two the 2nd power. first part of determinate
double e= b*(-1); //first part of formula. changes b to a negative
double f= 2*a;//divisore of problem
double ga= 4*a;
double g= ga*c;//second part of determinate
double h= d-g;//whole determinate
double i= Math.sqrt( (double) h); //sqrt b^2-4ac
double bc= e+i;//top of equation added
double cd= e-i;//top of equation subtracted
double de= bc/f;//whole equation
double ef= cd/f;//whole equation
System.out.println("The zeros of this equation are "+ de + " and "+ ef + ".");
}
}
When i run the program its out put is -
The form must be ax^2+bx+c to use this program.
Enter A: 1
Enter B: 2
Enter C: 8
The zeros of this equation are NaN and NaN.
Where it says NaN is where it messes up, i wrote all the other stuff in the code. My question is why does it say NaN and how do i fix it. i know NaN means not a number but where is my error and how do i fix it. please help!!!