Question 3.1

mail@pastecode.io avatar
unknown
java
a year ago
938 B
1
Indexable
Never
import java.util.Scanner;

public class QuestionThreePointOne
{
    public static void main(String[] args) 
    {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a, b c:");
        double a  = scanner.nextDouble();
        double b  = scanner.nextDouble();
        double c  = scanner.nextDouble();
        scanner.close();
        double discriminant  = ((b*b)-4*a*c);


        if(discriminant > 0)
        {
            double rootOne = (-b-(Math.sqrt(discriminant)))/(2*a);
            double rootTwo = (-b+(Math.sqrt(discriminant)))/(2*a);
            System.out.printf("The roots are %.2f and %.2f" ,rootOne, rootTwo);

        }
        if(discriminant == 0)
        {
            double rootOne = (-b)/(2*a);
            System.out.printf("The root is %.2f" ,rootOne);

        }
        if(discriminant < 0)
        {
            System.out.println("There are no roots ");

        }


    }
}