• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
49%
SHARE
TWEET

# Untitled

a guest Jun 19th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //by Ariel Duschanek-Myers
2. /////////////////////////////////////////////////////////////////
3.
4. import java.util.*;
5. import java.lang.Math;
6.
8. {
9. static Scanner console = new Scanner(System.in);
10. static double a, b, c;//global variables
11. //------------------Main Method---------------------
12. public static void main(String[] args)
13. {
14.
15. System.out.print("The General form of a quadratic equation is [ax]^2+bx+c.");
16. System.out.println();
17.
18. System.out.print("Enter A ");
19. a = console.nextDouble();
20. System.out.println();
21.
22. System.out.print("Enter B ");
23. b = console.nextDouble();
24. System.out.println();
25.
26. System.out.print("Enter C ");
27. c = console.nextDouble();
28. System.out.println();
29.
30. //Method call
31. test();
32. }//end main method
33. public static void test()
34. {
35. if ( a > 0 )
36. {   calcRoots(a, b, c);
37. }
38.             if (a == 0)
39.             {
41.                 System.out.println();
42.             }
43.             //end of If statements
44.
45.         }   //end test method
46. public static void calcRoots(double a, double b, double c)
47. {
48. double rootNeg = 0;
49. double rootPos = 0;
50.     rootNeg = ( + Math.sqrt( b * b - 4 * a * c)- b) / (2 * a);
51.     rootPos = ( - Math.sqrt( b * b - 4 * a * c)- b) / (2 * a);
52.
53.     System.out.println("Roots equal "+rootNeg+","+rootPos);
54.     }
55. }
RAW Paste Data
Top