-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPr_SquareRoot.java
More file actions
47 lines (40 loc) · 1.03 KB
/
Pr_SquareRoot.java
File metadata and controls
47 lines (40 loc) · 1.03 KB
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
public class SquareRoot
{
public static void main (String [] args)
{
double a = 3;
double b = 2.5;
double c = -0.5;
SquareRoot(a,b,c);
}
private static void SquareRoot (double a, double b, double c)
{
double tmp = Math.sqrt(b*b-4*a*c);
if (tmp > 0 && a !=0)
{
double x1 = (-b + tmp)/(2*a);
double x2 = (-b - tmp)/(2*a);
System.out.println("x1=" + x1);
System.out.println("x2=" + x2);
}
else if (tmp == 0 && a !=0)
{
double x1 = - b / (2*a);
double x2 = x1;
System.out.println("x1=" + x1);
System.out.println("x2=" + x2);
}
else if (tmp != 0 && a ==0)
{
double x1 = 0;
double x2 = x1;
System.out.println("x1=" + x1);
System.out.println("x2=" + x2);
}
else
{
System.out.println("x1=");
System.out.println("x2=");
}
}
}