Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //by Ariel Duschanek-Myers
- /////////////////////////////////////////////////////////////////
- import java.util.*;
- import java.lang.Math;
- public class quadraticEquation
- {
- static Scanner console = new Scanner(System.in);
- static double a, b, c;//global variables
- //------------------Main Method---------------------
- public static void main(String[] args)
- {
- System.out.print("The General form of a quadratic equation is [ax]^2+bx+c.");
- System.out.println();
- System.out.print("Enter A ");
- a = console.nextDouble();
- System.out.println();
- System.out.print("Enter B ");
- b = console.nextDouble();
- System.out.println();
- System.out.print("Enter C ");
- c = console.nextDouble();
- System.out.println();
- //Method call
- test();
- }//end main method
- public static void test()
- {
- if ( a > 0 )
- { calcRoots(a, b, c);
- }
- if (a == 0)
- {
- System.out.print("Equation is not quadratic.");
- System.out.println();
- }
- //end of If statements
- } //end test method
- public static void calcRoots(double a, double b, double c)
- {
- double rootNeg = 0;
- double rootPos = 0;
- rootNeg = ( + Math.sqrt( b * b - 4 * a * c)- b) / (2 * a);
- rootPos = ( - Math.sqrt( b * b - 4 * a * c)- b) / (2 * a);
- System.out.println("Roots equal "+rootNeg+","+rootPos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement