viewing paste Unknown #39204 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
import java.util.*;
 
class quadFormula
{
    static Scanner input = new Scanner(System.in); // Quadratic Formula
    public static void main(String[] args)
    {
        String contYorN = "Y";
        
        while (contYorN.equalsIgnoreCase("y"))
        {   
            
            System.out.println("This program will calculate the roots for a quadratic equation");
            System.out.print("Please input the constants in the following order(without the commas)' a, b, c ' .\nUse the following as a    reference : ax^2 +bx+c = 0");
            System.out.print(":");
            double a = input.nextDouble();
            double b = input.nextDouble();
            double c = input.nextDouble();
            double discrim = Math.pow(b,2)-(4*a*c); 
                if (discrim < 0)
                { 
                    System.out.println("There are not any real roots");
                    System.exit(0);
                } 
                else
                {
                    double rt1 =(int)((-b + Math.pow(discrim,.5))*1000)/(1000.0*2*a); // root 1
                    double rt2 =(int)((-b - Math.pow(discrim,.5))*1000)/(1000.0*2*a); // root 2 
                    System.out.println("The real roots are " +rt1 + " " +rt2);
                }
            
            System.out.print("\nWould you like to use this program again? Please type 'y' or 'n' : ");
            contYorN = input.nextLine();// Trying to make this program loop. 
            
 
    
        }   
    
    
    }
 
}
Viewed 1045 times, submitted by Guest.