Question : I thought the source code is right and it worked well a lot of times for example at functions like : x^2 + 4x +4 or 3x^2 +5x+1 but in some functions the output is NaN and i don't understand why (function that outputs NaN : 4x^2 - 2x +8
import java.util.*;
public class QuadGl {
/** * @param args */
public static void main(String[] args) {
double a,b,c,rechnung1,rechnung11,rechnung2,rechnung22,rechnung23,ergebnis1,ergebnis2;//BENÖTIGTE DATENTYPEN
Scanner input = new Scanner(System.in);
System.out.println("Bitte geben sie einen Wert für a ein : "); a = input.nextDouble();
System.out.println("Bitte geben sie einen Wert für b ein : "); b = input.nextDouble();
System.out.println("Bitte geben sie einen Wert für c ein : "); c = input.nextDouble();
//ERSTER RECHNUNGSSCHRITT DER P.Q.FORMEL
rechnung1 = b/a;//b=p
rechnung11 = c/a; //c=q
System.out.println(rechnung1);
System.out.println(rechnung11);
//ZWEITER RECHNUNGSSCHRITT
rechnung2 = (-rechnung1/2);// -b/2
rechnung22 = (rechnung1/2); // b/2
rechnung23 = Math.sqrt(( rechnung22 * rechnung22 -rechnung11));//
System.out.println(rechnung2);
System.out.println(rechnung22);
System.out.println(rechnung23);
ergebnis1 = rechnung2 + rechnung23;//-b/2 + b/2 ^2 - c
ergebnis2 = rechnung2 - rechnung23;//-b/2 - b/2 ^2 - c
System.out.println("x(1)= "+ ergebnis1);
System.out.println("x(2)= " + ergebnis2);
}
}