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) {...


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.




  1. public
    class Main {



  2. public
    static void main(String[] args) {

  3. double a = 2.3, b = 4, c = 5.6;

  4. double root1, root2;

  5. double determinant = b * b - 4 * a * c;



  6. if
    (determinant > 0) {

  7. root1 = (-b + Math.sqrt(determinant)) / (2 * a);

  8. root2 = (-b - Math.sqrt(determinant)) / (2 * a);

  9. out.format("root1 = %.2f and root2 = %.2f", root1, root2);

  10. }


  11. else
    if
    (determinant == 0) {

  12. root1 = root2 = -b / (2 * a);

  13. out.format("root1 = root2 = %.2f;", root1);

  14. }


  15. else
    {

  16. double real = -b / (2 * a);

  17. double imaginary = Math.sqrt(-determinant) / (2 * a);

  18. out.format("root1 = %.2f+%.2fi", real, imaginary);

  19. out.format("\nroot2 = %.2f-%.2fi", real, imaginary);

  20. }

  21. }

  22. }



Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here