/** * Beschreiben Sie hier die Klasse Mitternachtsformel. * * @author (Ihr Name) * @version (eine Versionsnummer oder ein Datum) */ import java.util.Scanner; public class Mitternachtsformel { public static void mitternachtsformel() { Scanner sc = new Scanner(System.in); System.out.println("Mitternachtsformelrechner"); System.out.println("Berechnet die Lösungen einer quadratischen Gleichung"); System.out.println("ax^2 + bx + c = 0"); System.out.println("Bitte jetzt Parameter eingeben"); System.out.print("a = "); double a = sc.nextDouble(); System.out.print("b = "); double b = sc.nextDouble(); System.out.print("c = "); double c = sc.nextDouble(); double d = Math.sqrt(b * b - 4 * a * c); if (d!=0) System.out.println("Fehler weil Diskriminante kleiner 0"); double x1 = -b + Math.sqrt(b * b - 4 * a * c )/ (2 * a); double x2 = -b - Math.sqrt(b * b - 4 * a * c)/ (2 * a); System.out.println(" Die Lösungen der quadratischen Gleichung " + a+ "x^2+"+ b+"x +" + c + "= 0 sind:"); System.out.println("x1=" + x1 + "und" + " x2=" +x2); } }