-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ8.java
More file actions
42 lines (24 loc) · 802 Bytes
/
Copy pathQ8.java
File metadata and controls
42 lines (24 loc) · 802 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class Q8 {
public static void main(String[] args) {
//2*(x^2)=5*x+3
//2 * (x^2) + (-5 * x) - 3 = 0
//using discriminant(Quadratic equation)
double x, a = 2, b = -5, c = -3;
double d = (Math.pow(b,2)-(4 * a * c));
if(d > 0) {
x = (-b - Math.sqrt(d)) / (2 * a);
System.out.println(x);
x = (-b + Math.sqrt(d))/(2 * a);
System.out.println(x);
}
if(d == 0) {
x = -b / (2 * a);
System.out.println(x);
System.out.println(x);
}
if(d < 0) {
System.out.println((-b / (2 * a)+" -i"+(( Math.sqrt(-1 * (Math.pow(b,2)-(4 * a * c))) ))/ (2 * a)));
System.out.println((-b / (2 * a)+" i"+(( Math.sqrt(-1 * (Math.pow(b,2)-(4 * a * c))) ))/ (2 * a)));
}
}
}