Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with this Quadratic Solver Java code. Here is my code: import java.util.Scanner; public class QuadraticSolver{ public static void main (String []

Can someone help me with this Quadratic Solver Java code.

image text in transcribed

Here is my code:

import java.util.Scanner;

public class QuadraticSolver{ public static void main (String [] args){ double a = 4.0; double b = -5.0; double c = 1.0;

double dis = b * b - 4.0 * a * c;

if (dis > 0.0) { double r1 = (-b + Math.pow(dis, 0.5)) / (2.0 * a); double r2 = (-b - Math.pow(dis, 0.5)) / (2.0 * a); System.out.println("The equation has two roots: " + r1 + " and " + r2); } else if (dis == 0.0) { double r1 = -b / (2.0 * a); System.out.println("The equation has one root: " + r1); } else { System.out.println("The equation has no root."); } } }

Output differs. See highlights below. Input Your output The equation has two real solutions, x1=1.0,x2=0.25 Expected output The equation has two roots: 0.38 and 2.62

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

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions