Advertisement
Quinoferd

Final Proj - Quadratic equation calc(fixing)

May 27th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. //2/5/2015
  2. //Quadratic Formula Calculator
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class QuadraticFormula {
  7.  
  8.     @SuppressWarnings({ "resource" })
  9.     public static void main(String[] args) {
  10.         double a1 = 0;
  11.         double b1 = 0;
  12.         double c1 = 0;
  13.        
  14.         Scanner getA= new Scanner(System.in);
  15.         System.out.println("Enter value for A");
  16.         a1=getA.nextDouble();
  17.        
  18.         Scanner getB= new Scanner(System.in);
  19.         System.out.println("Enter value for B");
  20.         b1=getB.nextDouble();
  21.        
  22.         Scanner getC= new Scanner(System.in);
  23.         System.out.println("Enter value for C");
  24.         c1=getC.nextDouble();
  25.        
  26.         //Discriminant
  27.         double discriminant= Math.pow(b1,2) - 4*a1*c1;
  28.        
  29.        
  30.         if  (discriminant<0){
  31.             double discrim2 = discriminant * -1;
  32.        
  33.             double y= 2 * a1;
  34.             double w1 = (b1 * -1)/y;
  35.             System.out.println("\t"+w1+"+-[(i"+'\u221A'+ discrim2+")/"+y+"]");
  36.             System.out.println("\t"+"The discriminant is "+discriminant);
  37.         }
  38.        
  39.         else{  
  40.         double v =  Math.sqrt(Math.pow(b1,2) - 4*a1*c1);
  41.         double y= 2 * a1;
  42.         double w1 = ((b1 * -1) + v)/y;
  43.         double w2 = ((b1 * -1) - v)/y;
  44.         System.out.println("x="+w1+"and "+ w2);
  45.         System.out.println("\t"+"The discriminant is "+discriminant);
  46.        
  47.         }//End If Statement
  48.        
  49.         System.out.println("\n"+"\n"+"Next equation");
  50.         main(args);
  51.    
  52.     }//End Main Method
  53. }//End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement