-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuadraticEquation.java
26 lines (26 loc) · 966 Bytes
/
QuadraticEquation.java
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
import java.util.Scanner;
public class QuadraticEquation{
public static void main(String[] Strings){
Scanner input = new Scanner(System.in);
System.out.print("Enter the value of a: ");
double a = input.nextDouble();
System.out.print("Enter the value of b: ");
double b = input.nextDouble();
System.out.print("Enter the value of c: ");
double c = input.nextDouble();
double d = b * b - 4.0 * a * c;
if (d > 0.0){
double r1 = (-b + Math.pow(d, 0.5)) / (2.0 * a);
double r2 = (-b - Math.pow(d, 0.5)) / (2.0 * a);
System.out.println("The roots are " + r1 + " and " + r2);
}
else if (d == 0.0){
double r1 = -b / (2.0 * a);
System.out.println("The root is " + r1);
}
else{
System.out.println("The equation has no real roots");
}
input.close();
}
}