Quadratic equation

Report a typo

Complete a Java program that calculates the roots of a quadratic equation using the quadratic formula. The quadratic equation is given by:

ax2+bx+c=0ax^2+bx+c=0

The roots of this equation can be found using the quadratic formula: x=b±D2ax=\dfrac{−b±\sqrt{D}}{2a} where DD is a discriminant and is calculated as b24acb^2-4ac.

Note: Let's assume for this task that calculated discriminant will always be positive, and hence the roots of the equation will never be imaginary.

Fill in the gaps with the relevant elements
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        double c = scanner.nextDouble();

        double discriminant =  - 4 * a * c;
        double root1 = (-b + Math.sqrt(discriminant)) / ;
        double root2 = ( - Math.sqrt(discriminant)) / (2 * a);

        System.out.println("Roots: " + root1 + ", " + root2);
    }
}
b-bb * b2 * ab * 2(2 * a)
___

Create a free account to access the full topic