Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

JAVA Please check the code I wrote. Then please revise it. Exercise 3.8 asked you to write a method called quadratic that solves quadratic equations

image text in transcribed

JAVA Please check the code I wrote. Then please revise it.

Exercise 3.8 asked you to 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 a x2 +bx+c = 0. The formula for solving a quadratic equation is: X= b+Vb2 - 4ac 2a Here are some example equations and their roots: equation x2 - 7x + 12 x2 + 3x + 2 call quadratic(1, -7, 12); quadratic(1, 3, 2); output First root = 4.0 First root = -1.0 Second root - 3.0 Second root = -2.0 But for some values of a, b, and c, the formula does not find any valid roots. Under what conditions would this formula fail? Modify the quadratic method so that it will reject invalid values of a, b, or c by throwing an IllegalArgumentException. (You may want to go back and complete the exercise in the previous chapter first.) Type your solution here: 1 public static void quadratic(int a, int b, int c) throws IllegalArgumentException{ float fr (- 6+ (b*b-4*a*c)^(1/2))/(2*a); 3 float sc = - b - (b*b-4*a*c)^(1/2)/(2*a); System.out.println("First root = " + fr); System.out.println("Second root = + SC); 7 8 9 4 5 10)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions