Respuesta :

Answer:

The program to this question can be given as:

Program:

//import package.

import java.util.*;

public class quadratic           //define class.

{

public static void main(String[] args) //define main method

{

double a,b,c;          //decalre varibale.

Scanner in=new Scanner(System.in);       //creating scanner class object.

System.out.print("Enter coefficient a: ");          //print message.

a=in.nextDouble();                      //user input.

System.out.print("Enter coefficient b: ");

b=in.nextDouble();

System.out.print("Enter coefficient c: ");

c=in.nextDouble();

solve(a,b,c);                //calling function.

}

public static void solve(double a,double b,double c)      //define method.

{

double dis;  //define variable.

dis=b*b-4*a*c;

System.out.println("The roots of "+a+"x^2 + "+b+"x + "+"("+c +")" +" are:");

//conditional statement.

if(a==0)    //by definition-denominator will be 0

{

System.out.println("Error: no real roots exist");

}

else if(dis<0)         //by definition, negative discriminant means roots are imagenary

{

System.out.println("Error: no real roots exist\n");

}

else                          //get the 2 roots

{

dis=Math.sqrt(dis);

System.out.println("first root= "+(-b+dis)/(2*a)+"\nSecond root= "+(-b-dis)/(2*a));

}

}

}

Output:

Enter coefficient a: 6

Enter coefficient b: 11

Enter coefficient c: -35

The roots of  6.0x^2 + 11.0"x +(-35)  are:

first root= 1.666666666667

Second root=-3.5

Explanation:

In the above program firstly we import packages for the user input. Then we define class. In this class we define a main method and function i.e solve function. In the main method we create the scanner class object and input the value from the user and pass the value to the function and call the function. In the solve function, we use the conditional statement that checks any of the input values is not equal to 0. if any value is equal to 0 it prints error message otherwise it prints the quadratic value and its roots.

ACCESS MORE