Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ThreeOne
- {
- public static void main (String [] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("What is a: ");
- double a = input.nextDouble();
- System.out.println("What is b: ");
- double b = input.nextDouble();
- System.out.println("What is c: ");
- double c = input.nextDouble();
- double discriminant = Math.pow(Math.pow(b, 2) - (4 * a * c), .5);
- double r1 = (-1 * b + discriminant) / (2 * a);
- double r2 = (-1 * b - discriminant) / (2 * a);
- if (discriminant > 0)
- {
- System.out.println("The roots are " + r1 + " and " + r2);
- }
- else if (discriminant == 0)
- {
- System.out.println("The root is" + r1);
- }
- else
- {
- System.out.println("The equation has no real roots");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement