/* Author: Seth Riedel
 * Purpose: Do the quadratic formula really fast
 * Version 1.3 (fixed error with imaginary answers)
 * Get newest version at http://github.com/brovie96/quadratic-formula
 */
import java.util.Scanner; //import scanner
public class QuadraticFormula
{
   public static void main(String[] args)
   {
      Scanner input = new Scanner(System.in); //create scanner
      //define variables
      double a;
      double b;
      double c;
      double discrim;
      double discrimAginary;
      double firstAnswer;
      double secondAnswer;
      double firstAnswerI;
      double secondAnswerI;
      //get input
      System.out.print("Enter a value for a: ");
      a = input.nextDouble();
      System.out.print("Enter a value for b: ");
      b = input.nextDouble();
      System.out.print("Enter a value for c: ");
      c = input.nextDouble();
      //calculations
      discrim = Math.sqrt(Math.pow(b,2) - 4*a*c);
      firstAnswer = (-b + discrim)/(2*a);
      secondAnswer = (-b - discrim)/(2*a);
      discrimAginary = Math.sqrt(-(Math.pow(b,2) - 4*a*c));
      firstAnswerI = (-b + discrimAginary)/(2*a);
      secondAnswerI = (-b - discrimAginary)/(2*a);
      //print result
      if (firstAnswer == secondAnswer) System.out.printf("The answer is %f.%n",firstAnswer);
      else if (Double.isNaN(firstAnswer))
      {
         if (Double.isNaN(secondAnswer)) System.out.printf("The answers are %fi and %fi.%n",firstAnswerI,secondAnswerI);
         else System.out.printf("The answers are %fi and %f.%n",firstAnswerI,secondAnswer);
      } //end if
      else if (Double.isNaN(secondAnswer)) System.out.printf("The answers are %f and %fi.%n",firstAnswer,secondAnswerI);
      else System.out.printf("The answers are %f and %f.%n",firstAnswer,secondAnswer);
   } //end main method
} //end class
@@ -84,45 +84,21 @@
 n 1.
-3 (fixed error with imaginary answers
+4 (optimizing
 )%0D%0A 
@@ -1339,305 +1339,15 @@
 NaN(
-firstAnswer))%0D%0A      %7B%0D%0A         if (Double.isNaN(secondAnswer)) System.out.printf(%22The answers are %25fi and %25fi.%25n%22,firstAnswerI,secondAnswerI);%0D%0A         else System.out.printf(%22The answers are %25fi and %25f.%25n%22,firstAnswerI,secondAnswer);%0D%0A      %7D //end if%0D%0A      else if (Double.isNaN(secondAnswer
+discrim
 )) S
@@ -1378,24 +1378,25 @@
 swers are %25f
+i
  and %25fi.%25n%22
@@ -1399,32 +1399,33 @@
 .%25n%22,firstAnswer
+I
 ,secondAnswerI);

Version 1.4