Question: How do I add the highlighted decimals for these expected outputs? My Java Code: import java.util.Scanner; import java.text.DecimalFormat; public class QuadraticSolver { public static void

How do I add the highlighted decimals for these expected outputs?
My Java Code:
import java.util.Scanner; import java.text.DecimalFormat;
public class QuadraticSolver { public static void main(String[] args) { Scanner input = new Scanner(System.in); double a = input.nextDouble(); double b = input.nextDouble(); double c = input.nextDouble(); DecimalFormat df = new DecimalFormat("#.##");
double dis = b * b - 4.0 * a * c;
if (dis > 0.0) { double r1 = (-b + Math.sqrt(dis)) / (2.0 * a); double r2 = (-b - Math.sqrt(dis)) / (2.0 * a); System.out.println("The equation has two roots: " + df.format(r1) + " and " + df.format(r2)); } else if (dis == 0.0) { double r1 = -b / (2.0 * a); System.out.println("The equation has one root: " + r1); } else { double realPart = -b / (2.00 * a); double imagPart = Math.sqrt(-dis) / (2.00 * a); System.out.println("The equation has two imaginary roots: " + df.format(realPart) + " + " + df.format(imagPart) + "i and " + df.format(realPart) + " - " + df.format(imagPart) + "i"); } } }
Output differs. See highlights below. Input Your output Expected output Compare output x 0/4 Output differs. See highlights below. Input Your output The equation has two imaginary roots: 2.5+1.66i and 2.51.66i Expected output The equation has two imaginary roots: 2.50+1.66i and 2.501.66i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
