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
Q4. Consider the following two design alternatives. Walmart Walmart Store locartion 1 * capacity - Associate Name 1 id position Design Alternative "A" Store locartion 1 capacity Associate Name 1 * id position Design Alternative "B" a) Explain the semantic differences between the two designs, if any. b) Explain the differences in how each design alternative may be implemented in Java. c) which design alternative may require more storage requirement in your opinion, and why?
Design a schematic for a compartmental model that includes compartments, flows, and parameters with their respective units, using Figure 1 as a guide. For each flow, determine whether it is best represented by a first-order transfer, a Michaelis-Menten saturable process, or a different method.
9. Consider the diagram on the right. Using this diagram and the four following terms: (a) lonization Energy, (b) Electron Affinity, (c) Mulliken Electronegativity, and (d) Polarizability, label each arrow with the correct term (you can label the arrows with the corresponding letter for space purposes). Please provide labels for both species X and Y. lonization Limit b) Indicate why. Energy- Species X Species Y Which species (X or Y) has the highest electronegativity? Which has the largest polarizability? c)( 2) Consider BH3 (boron trihydride) and TIH3 (thallium trihydride). Which one is more polarizable and why? Which one would have stronger intermolecular forces and why?

Chapter 3 Solutions

MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version

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