bartleby

Videos

Question
Book Icon
Chapter 3, Problem 3.1PE
Expert Solution & Answer
Check Mark
Program Plan Intro

Algebra: solve quadratic equation

Program Plan:

  • Import the required packages.
  • Create a class Exercise
    • Define the main method.
    • Define the scanner input and prompt user to enter the value of a,b,c.
    • Get the input.
    • Calculate the discriminant value.
    • Condition to validate the discriminant value.
    • After validation the value gets of the root gets calculated based on the condition.
    • Display the result of roots.
Program Description Answer

The below program is used to solve the quadratic equation:

Explanation of Solution

Program:

//import the required packages

import java.util.Scanner;

//define the class exercise

public class Exercise

{

public static void main(String[] args)

{

//scanner input

Scanner input = new Scanner(System.in);

/*prompt user to enter the value of the a,b and c*/

System.out.print("Enter a, b, c: ");

//get value of a

double a = input.nextDouble();

//get value of b

double b = input.nextDouble();

//get value of c

double c = input.nextDouble();

//equation to calculate the discriminant

double discriminant = b * b - 4 * a * c;

//condition to validate the discriminant value

if (discriminant < 0)

{

//display result

System.out.println("The equation has no real roots");

}

//condition to validate the discriminant value

else if (discriminant == 0)

{

//equation to calculate the root value

double r1 = -b / (2 * a);

//display result

System.out.println("The equation has one root " + r1);

}

//condition to validate the discriminant value

else

{

// (discriminant > 0)

//equation to calculate the root value

double r1 = (-b + Math.pow(discriminant, 0.5)) / (2 * a);

//equation to calculate the root value

double r2 = (-b - Math.pow(discriminant, 0.5)) / (2 * a);

//display result

System.out.println("The equation has two roots " + r1 + " and " + r2);

}

}

}

Sample Output

Enter a, b, c: 1

2.0

1

The equation has one root -1.0

Additional Output 1:

Enter a, b, c: 1.0

3

1

The equation has two roots -0.3819660112501051 and -2.618033988749895

Additional Output 2:

Enter a, b, c: 1

2

3

The equation has no real roots

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
05:55
Students have asked these similar questions
Python - Need help! How do I have an input in turtle to display my name below the circle it draws and another input to display my age written below that? Code: import turtlebackground = "#FFFFFF" def draw_circle(radius, line_color, fill_color): my_turtle.color(line_color) my_turtle.fillcolor(fill_color) my_turtle.begin_fill() my_turtle.circle(radius) my_turtle.end_fill() def move_turtle(x, y): my_turtle.penup() my_turtle.goto(x, y) my_turtle.pendown() turtle.done()
Need help fixing my python code! Images attached on the required modficications I dont know how to do. Simpler the better.Code: (in images)
Answer all of the questions with steps by step explanation to every question.

Chapter 3 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Chapter 3.5, Problem 3.5.3CP Chapter 3.6, Problem 3.6.1CP Chapter 3.6, Problem 3.6.2CP Chapter 3.6, Problem 3.6.3CP Chapter 3.6, Problem 3.6.4CP Chapter 3.7, Problem 3.7.1CP Chapter 3.7, Problem 3.7.2CP Chapter 3.9, Problem 3.9.1CP Chapter 3.10, Problem 3.10.1CP Chapter 3.10, Problem 3.10.2CP Chapter 3.10, Problem 3.10.3CP Chapter 3.10, Problem 3.10.4CP Chapter 3.10, Problem 3.10.5CP Chapter 3.10, Problem 3.10.6CP Chapter 3.10, Problem 3.10.7CP Chapter 3.10, Problem 3.10.8CP Chapter 3.10, Problem 3.10.9CP Chapter 3.10, Problem 3.10.10CP Chapter 3.10, Problem 3.10.11CP Chapter 3.11, Problem 3.11.1CP Chapter 3.12, Problem 3.12.1CP Chapter 3.13, Problem 3.13.1CP Chapter 3.13, Problem 3.13.2CP Chapter 3.13, Problem 3.13.3CP Chapter 3.13, Problem 3.13.4CP Chapter 3.13, Problem 3.13.5CP Chapter 3.14, Problem 3.14.1CP Chapter 3.14, Problem 3.14.2CP Chapter 3.14, Problem 3.14.3CP Chapter 3.14, Problem 3.14.4CP Chapter 3.15, Problem 3.15.1CP Chapter 3.15, Problem 3.15.2CP Chapter 3.15, Problem 3.15.3CP Chapter 3.15, Problem 3.15.4CP Chapter 3, Problem 3.1PE Chapter 3, Problem 3.2PE Chapter 3, Problem 3.3PE Chapter 3, Problem 3.4PE Chapter 3, Problem 3.5PE Chapter 3, Problem 3.6PE Chapter 3, Problem 3.7PE Chapter 3, Problem 3.8PE Chapter 3, Problem 3.9PE Chapter 3, Problem 3.10PE Chapter 3, Problem 3.11PE Chapter 3, Problem 3.12PE Chapter 3, Problem 3.13PE Chapter 3, Problem 3.14PE Chapter 3, Problem 3.15PE Chapter 3, Problem 3.16PE Chapter 3, Problem 3.17PE Chapter 3, Problem 3.18PE Chapter 3, Problem 3.19PE Chapter 3, Problem 3.20PE Chapter 3, Problem 3.21PE Chapter 3, Problem 3.22PE Chapter 3, Problem 3.23PE Chapter 3, Problem 3.24PE Chapter 3, Problem 3.25PE Chapter 3, Problem 3.26PE Chapter 3, Problem 3.27PE Chapter 3, Problem 3.28PE Chapter 3, Problem 3.29PE Chapter 3, Problem 3.30PE Chapter 3, Problem 3.31PE Chapter 3, Problem 3.32PE Chapter 3, Problem 3.33PE Chapter 3, Problem 3.34PE

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
The equivalent resultant force and couple moment acting at point O.

INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)

Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    Text book image
    C++ for Engineers and Scientists
    Computer Science
    ISBN:9781133187844
    Author:Bronson, Gary J.
    Publisher:Course Technology Ptr
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Text book image
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
    Computer Science
    ISBN:9780357392676
    Author:FREUND, Steven
    Publisher:CENGAGE L
    Algebraic Expressions – Algebra Basics; Author: TabletClass Math;https://www.youtube.com/watch?v=U-7nq7OG18s; License: Standard YouTube License, CC-BY
    Python Tutorial for Beginners 3 - Basic Math, Mathematical Operators and Python Expressions; Author: ProgrammingKnowledge;https://www.youtube.com/watch?v=Os4gZUI1ZlM; License: Standard Youtube License