-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquareRoot.java
48 lines (39 loc) · 1.04 KB
/
SquareRoot.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class SquareRoot {
public static void main(String[] args) {
double a = 3;
double b = 2.5;
double c = -0.5;
if (a == 0 && b != 0)
{
System.out.println("x1=" + (0.0 - c / b));
System.out.println("x2=" + (0.0 - c / b));
}
else if (a == 0 && b == 0)
{
System.out.println("x1=");
System.out.println("x2=");
}
else
{
double d = b * b - 4d * a * c;
if (d > 0)
{
double x1 = (-b + Math.sqrt(d)) / (2d * a);
double x2 = (-b - Math.sqrt(d)) / (2d * a);
System.out.println("x1=" + x1);
System.out.println("x2=" + x2);
}
else if (d == 0)
{
double x = -b / (2d * a);
System.out.println("x1=" + x);
System.out.println("x2=" + x);
}
else
{
System.out.println("x1=");
System.out.println("x2=");
}
}
}
}