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.66iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started