/*
* File: Quadratic.java
* --------------------
* This program is a stub for the Quadratic problem, which finds the
* roots of the quadratic equation.
*/
import acm.program.*;
public class Quadratic extends ConsoleProgram {
public void run() {
// You fill this in
println("Enter coeficients for the quadratic equation");
int a = readInt("a:");
int b = readInt("b:");
int c = readInt("c:");
int m = b * b - 4 * a * c;
double x1, x2, y;
if (m < 0)
println("the equation has no real solutions.");
else {
y = Math.sqrt(m);
x1 = (-b + y) / (2 * a);
x2 = (-b - y) / (2 * a);
println("the first solution is: " + x1);
println("the second solution is: " + x2);
}
}
}
* File: Quadratic.java
* --------------------
* This program is a stub for the Quadratic problem, which finds the
* roots of the quadratic equation.
*/
import acm.program.*;
public class Quadratic extends ConsoleProgram {
public void run() {
// You fill this in
println("Enter coeficients for the quadratic equation");
int a = readInt("a:");
int b = readInt("b:");
int c = readInt("c:");
int m = b * b - 4 * a * c;
double x1, x2, y;
if (m < 0)
println("the equation has no real solutions.");
else {
y = Math.sqrt(m);
x1 = (-b + y) / (2 * a);
x2 = (-b - y) / (2 * a);
println("the first solution is: " + x1);
println("the second solution is: " + x2);
}
}
}