-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuadraticExp.java
More file actions
25 lines (23 loc) · 957 Bytes
/
QuadraticExp.java
File metadata and controls
25 lines (23 loc) · 957 Bytes
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
import java.util.Scanner;
public class QuadraticExp {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
double r1, r2;
int a = reader.nextInt();
int b = reader.nextInt();
int c = reader.nextInt();
int d = (b * b) - (4 * a * c);
if (d == 0) {
r1 = r2 = (double) (-b) / (2 * a);
System.out.println("Roots are Real and Equal and they are :" + r1 + " " + r2);
} else if (d > 0) {
r1 = (double) (-b + (Math.sqrt(d))) / (2 * a);
r2 = (double) (-b - (Math.sqrt(d))) / (2 * a);
System.out.println("Roots are Real and Distinct and they are :" + r1 + " " + r2);
} else {
r1 = (double) (-b + (Math.sqrt(d))) / (2 * a);
r2 = (double) (-b - (Math.sqrt(d))) / (2 * a);
System.out.println("Roots are Imaginary!!!, and they are :" + r1 + " " + r2);
}
}
}