Hey yall I got this program which compiles runs but when it prints stuff out it prints out it just prints out NaN for the value of firstroot and secondroot so in example if d > 0 it prints this out.
The descriminate is NaN NaN and the the roots are both real
I have no clue what NaN means but any help would be great (im guessing its with my parameters and how im passing them to the different methods, but i may be wrong)
import java.util.*;
public class Quads
{
static Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
double a = 0;
double b = 0;
double c = 0;
double d = 0;
double firstroot = 0;
double secondroot = 0;
double k = 0;
while(a == 0)
{
System.out.println("Enter in a number for a");
a = input.nextDouble();
System.out.println("Enter in a number for b");
b = input.nextDouble();
System.out.println("Enter in a number for c");
c = input.nextDouble();
if(a == 0)
{
System.out.println("a cannot equal zero please enter in another number");
a = input.nextDouble();
firstroot = findd(b, a, c, d);
secondroot = findsecond(b, a, c, d);
}
else
{
firstroot = findd(b,a, c, d);
secondroot = findsecond(b, a, c, d);
}
}
if(d>0)
{
dgreater(firstroot, secondroot);
}
else if(d==0)
{
dequal(firstroot, secondroot);
}
else
{
dless();
}
}
public static double findd(double b, double a, double c, double d)
{
double k = 0;
double w = 0;
d = b*b - 4*a*c;
k = Math.sqrt(d);
w = (-b/2*a) + (k/2*a);
return w;
}
public static double findsecond(double b, double a, double c, double d)
{
double k = 0;
double i = 0;
d = b*b - 4*a*c;
k = Math.sqrt(d);
i = (-b/2*a) - (k/2*a);
return i;
}
public static void dgreater(double firstroot, double secondroot)
{
System.out.println("The descriminate is " + firstroot + " " + secondroot + " and the the roots are both real");
}
public static void dequal(double firstroot, double secondroot)
{
System.out.println("The descriminate is " + firstroot + " " + secondroot + " and there is one real root");
}
public static void dless()
{
System.out.println("There are no real roots");
}
}