Below is a java program to find roots of quadratic equation. Please explain each line of code if what it does in the program when executed. public class Main { public static void main(String[] args) { double a = 2.3, b = 4, c = 5.6; double root1, root2; double determinant = b * b - 4 * a * c; if (determinant > 0) { root1 = (-b + Math.sqrt(determinant)) / (2 * a); root2 = (-b - Math.sqrt(determinant)) / (2 * a); out.format("root1 = %.2f and root2 = %.2f", root1, root2); } else if (determinant == 0) { root1 = root2 = -b / (2 * a); out.format("root1 = root2 = %.2f;", root1); } else { double real = -b / (2 * a); double imaginary = Math.sqrt(-determinant) / (2 * a); out.format("root1 = %.2f+%.2fi", real, imaginary); out.format("\nroot2 = %.2f-%.2fi", real, imaginary); } } }
Below is a java program to find roots of quadratic equation. Please explain each line of code if what it does in the program when executed. public class Main { public static void main(String[] args) { double a = 2.3, b = 4, c = 5.6; double root1, root2; double determinant = b * b - 4 * a * c; if (determinant > 0) { root1 = (-b + Math.sqrt(determinant)) / (2 * a); root2 = (-b - Math.sqrt(determinant)) / (2 * a); out.format("root1 = %.2f and root2 = %.2f", root1, root2); } else if (determinant == 0) { root1 = root2 = -b / (2 * a); out.format("root1 = root2 = %.2f;", root1); } else { double real = -b / (2 * a); double imaginary = Math.sqrt(-determinant) / (2 * a); out.format("root1 = %.2f+%.2fi", real, imaginary); out.format("\nroot2 = %.2f-%.2fi", real, imaginary); } } }
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
Related questions
Question
Below is a java program to find roots of quadratic equation. Please explain each line of code if what it does in the program when executed.
- public class Main {
- public static void main(String[] args) {
- double a = 2.3, b = 4, c = 5.6;
- double root1, root2;
- double determinant = b * b - 4 * a * c;
- if (determinant > 0) {
- root1 = (-b + Math.sqrt(determinant)) / (2 * a);
- root2 = (-b - Math.sqrt(determinant)) / (2 * a);
- out.format("root1 = %.2f and root2 = %.2f", root1, root2);
- }
- else if (determinant == 0) {
- root1 = root2 = -b / (2 * a);
- out.format("root1 = root2 = %.2f;", root1);
- }
- else {
- double real = -b / (2 * a);
- double imaginary = Math.sqrt(-determinant) / (2 * a);
- out.format("root1 = %.2f+%.2fi", real, imaginary);
- out.format("\nroot2 = %.2f-%.2fi", real, imaginary);
- }
- }
- }
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT