Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method called quadratic that solves quadratic equations and prints their

ID: 3630169 • Letter: W

Question

Write a method called quadratic that solves quadratic equations and prints their roots. Recall that a quadratic equation is a polynomial equation in terms of a variable x of the form ax2 + b + c = 0. The formula for solving a quadratic equation is:

[-b +/- (b^2 -4ac)^(1/2)]/ 2a

Here are some example equations and their roots:

x2 - 7x + 12
quadratic(1, -7, 12);
First root = 4.0
Second root = 3.0

Your method should accept the coefficients a, b, and c as parameters and should print the roots of the equation. You may assume that the equation has two real roots, though mathematically this is not always the case.

Also, there should be two roots, one the result of the addition, the other, the result of the subtraction. Print the root resulting from the addition first.

Explanation / Answer

public void quadratic(double a,double b,double c ) ( //declare two variable to store the answer of the quadratic equation. double ans1 = 0.0; double ans2 = 0.0; //formula of solving the equation. ans 1 = ((-b) - Math.sqrt(Math.pow(b,2) - 4*a*c))/(2*a); ans 2 = ((-b) + Math.sqrt(Math.pow(b,2) - 4*a*c))/(2*a); //printing of the answers System.out.println(ans1); System.out.println(ans2); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote