import java.util.Scanner; public class Week3_QuadraticFormula { public static void main(String[] args) { double a, b, c, x,
Question:
import java.util.Scanner; public class Week3_QuadraticFormula
{
public static void main(String[] args) {
double a, b, c, x, y; Scanner keyboard = new Scanner(System.in);
System.out.println("Input the value of a: "); a = keyboard.nextDouble();
System.out.println("Input the value of b: "); b = keyboard.nextDouble();
System.out.println("Input the value of c: "); c = keyboard.nextDouble();
x = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); y = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
System.out.println("The solution for x is " + x);
System.out.println("The solution for y is " + y);
}
}
Add validation checks (IFs) to this program to make sure the quadratic formula will work with the data.
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch