Trying to get printf to work
I made a program to calculate the roots of quadratic equation by the user entering the A, B, and C values. Here is what I have so far
package quadratic;
import java.util.Scanner;
publicclass Quadratic{
/**
* @param args
*/
publicstaticvoid main(String[] args){
// TODO Auto-generated method stub
double A, B, C;
Scanner input =new Scanner (System.in);
System.out.println("Enter A, then B, then C");
A = input.nextDouble();
B = input.nextDouble();
C = input.nextDouble();
System.out.printf("Root one is %g", negBplus(A, B, C));
}
publicstaticdouble negBplus(double a,double b,double c){
return ((-b + Math.sqrt(Math.pow(b, 2) - 4*a*c)) / 2*a);
}
publicstaticdouble negBminus(double a,double b,double c){
return ((-b - Math.sqrt(Math.pow(b, 2) - 4*a*c)) / 2*a);
}
}
When I try to run the program, I get "Root one is NaN." And thats when I use the %g sign. I have used other letters like %f, %d, and %e, but none seem to work. I have tried to make the entire program run on ints but it says that Math.sqrt, and Math.pow are both equations that produce doubles. How can I get it so that it properly displays the roots?

