Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Lab03 {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. Scanner in = new Scanner(System.in);
  9.  
  10. double a, b, c, discriminant;
  11.  
  12. System.out.print("Please enter the value of a,b,c: ");
  13.  
  14. a = in.nextDouble();
  15.  
  16. b = in.nextDouble();
  17.  
  18. c = in.nextDouble();
  19.  
  20. discriminant = b * b - 4.0 * a * c;
  21.  
  22. if (discriminant < 0) {
  23.  
  24. System.out.println("The equation has no real roots.");
  25.  
  26. } else if (discriminant == 0.0) {
  27.  
  28. System.out.println("The root is " + (-b / (2.0 * a)));
  29.  
  30. } else {
  31.  
  32. System.out.print("The roots are ");
  33.  
  34. System.out.print((-b + Math.pow(discriminant, 0.5)) / (2.0 * a));
  35.  
  36. System.out.print(" and ");
  37.  
  38. System.out.println((-b - Math.pow(discriminant, 0.5)) / (2.0 * a));
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement