forked from prashantkalokhe/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.java
27 lines (25 loc) · 1.25 KB
/
root.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
27
import java.util.Scanner;
public class root {
public static void main(String args[]) {
double a_1684, b_1684, c_1684, discriminant_1684, root1_1684, root2_1684, realpart_1684, imagpart_1684;
Scanner sc_1684 = new Scanner(System.in);
System.out.print("Enter Coefficents a,b and c :");
a_1684 = sc_1684.nextDouble();
b_1684 = sc_1684.nextDouble();
c_1684 = sc_1684.nextDouble();
sc_1684.close();
discriminant_1684 = b_1684 * b_1684 - 4 * a_1684 * c_1684;
if (discriminant_1684 > 0) {
root1_1684 = (-b_1684 + Math.pow(discriminant_1684, 0.5)) / 2 * a_1684;
root2_1684 = (-b_1684 - Math.pow(discriminant_1684, 0.5)) / 2 * a_1684;
System.out.println("root1=" + root1_1684 + " and root2=" + root2_1684);
} else if (discriminant_1684 == 0) {
root1_1684 = root2_1684 = -b_1684 / 2 * a_1684;
System.out.println("root1 and root2=" + root1_1684);
} else {
realpart_1684 = -b_1684 / 2 * a_1684;
imagpart_1684 = Math.pow(-discriminant_1684, 0.5) / 2 * a_1684;
System.out.println("root1=" + realpart_1684 + "+" + imagpart_1684 + "i and root2=" + realpart_1684 + "-" + imagpart_1684 + "i");
}
}
}