Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.text.*;
- public class Quiz1practice
- {
- public static void main( String [] args )
- {
- Scanner input = new Scanner(System.in);
- double a = inputMeth( input );
- double b = inputMeth( input );
- double c = inputMeth( input );
- double deter = determinant(a, b, c);
- if (deter < 0){
- System.out.println("No real solutions" );
- }
- else if( deter > 0)
- {
- double x1 = (-b - Math.sqrt(deter))/(2*a);
- double x2 = (-b + Math.sqrt(deter))/(2*a);
- System.out.format("The roots of your quadratic formula are " + x1 + " and " + x2);
- }
- else
- {
- double x3 = -b/(2*a);
- }
- }
- public static double inputMeth(Scanner input)
- {
- System.out.print( "Please enter a number --> " );
- return input.nextDouble();
- }
- public static double determinant(double a, double b, double c)
- {
- double discriminant = Math.pow(b, 2) -4*a*c;
- return discriminant;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement