Question: Write Java code ( Algebra: solve quadratic equations ) The two roots of a quadratic equation a x 2 + b x + c =

Write Java code
(Algebra: solve quadratic equations)
The two roots of a quadratic equation ax2+bx+c=0 can be obtained using the following formula:
r1=-b+(b2-4ac)22a,r2=-b-(b2-4ac)22a
b2-4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots.
Write a program that prompts the user to enter values for ar,b, and c and displays the result based on the discriminant. If the discriminant is positive, display two roots. If the discriminant is 0,
display one root. Otherwise, display "The equation has no real roots".
Note that you can use pow(x,0.5 to compute x2.
Sample Run 1
Enter *a,b,c:*13.5*45*2*12.4
The roots are -0.301483* and *-3.04666
Sample Run 2
Enter *a,b,c : -112.0-1
The root is --1.0
Sample Run 3
Enter a, b, c: 112*3
The equation has no real roots
Write Java code ( Algebra: solve quadratic

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!