Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions