Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //2/5/2015
- //Quadratic Formula Calculator
- import java.util.Scanner;
- public class QuadraticFormula {
- @SuppressWarnings({ "resource" })
- public static void main(String[] args) {
- double a1 = 0;
- double b1 = 0;
- double c1 = 0;
- Scanner getA= new Scanner(System.in);
- System.out.println("Enter value for A");
- a1=getA.nextDouble();
- Scanner getB= new Scanner(System.in);
- System.out.println("Enter value for B");
- b1=getB.nextDouble();
- Scanner getC= new Scanner(System.in);
- System.out.println("Enter value for C");
- c1=getC.nextDouble();
- //Discriminant
- double discriminant= Math.pow(b1,2) - 4*a1*c1;
- if (discriminant<0){
- double discrim2 = discriminant * -1;
- double y= 2 * a1;
- double w1 = (b1 * -1)/y;
- System.out.println("\t"+w1+"+-[(i"+'\u221A'+ discrim2+")/"+y+"]");
- System.out.println("\t"+"The discriminant is "+discriminant);
- }
- else{
- double v = Math.sqrt(Math.pow(b1,2) - 4*a1*c1);
- double y= 2 * a1;
- double w1 = ((b1 * -1) + v)/y;
- double w2 = ((b1 * -1) - v)/y;
- System.out.println("x="+w1+"and "+ w2);
- System.out.println("\t"+"The discriminant is "+discriminant);
- }//End If Statement
- System.out.println("\n"+"\n"+"Next equation");
- main(args);
- }//End Main Method
- }//End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement