Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.*;
  2. import java.text.*;
  3. public class Quiz1practice
  4. {
  5. public static void main( String [] args )
  6. {
  7. Scanner input = new Scanner(System.in);
  8. double a = inputMeth( input );
  9. double b = inputMeth( input );
  10. double c = inputMeth( input );
  11. double deter = determinant(a, b, c);
  12. if (deter < 0){
  13. System.out.println("No real solutions" );
  14. }
  15.  
  16. else if( deter > 0)
  17. {
  18. double x1 = (-b - Math.sqrt(deter))/(2*a);
  19. double x2 = (-b + Math.sqrt(deter))/(2*a);
  20. System.out.format("The roots of your quadratic formula are " + x1 + " and " + x2);
  21. }
  22. else
  23. {
  24. double x3 = -b/(2*a);
  25. }
  26. }
  27. public static double inputMeth(Scanner input)
  28. {
  29. System.out.print( "Please enter a number --> " );
  30. return input.nextDouble();
  31. }
  32. public static double determinant(double a, double b, double c)
  33. {
  34. double discriminant = Math.pow(b, 2) -4*a*c;
  35. return discriminant;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement