Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ThreeOne
  4. {
  5. public static void main (String [] args)
  6. {
  7. Scanner input = new Scanner(System.in);
  8. System.out.println("What is a: ");
  9. double a = input.nextDouble();
  10. System.out.println("What is b: ");
  11. double b = input.nextDouble();
  12. System.out.println("What is c: ");
  13. double c = input.nextDouble();
  14.  
  15. double discriminant = Math.pow(Math.pow(b, 2) - (4 * a * c), .5);
  16. double r1 = (-1 * b + discriminant) / (2 * a);
  17. double r2 = (-1 * b - discriminant) / (2 * a);
  18. if (discriminant > 0)
  19. {
  20. System.out.println("The roots are " + r1 + " and " + r2);
  21. }
  22. else if (discriminant == 0)
  23. {
  24. System.out.println("The root is" + r1);
  25. }
  26. else
  27. {
  28. System.out.println("The equation has no real roots");
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement