-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeterminan.java
More file actions
42 lines (41 loc) · 845 Bytes
/
Copy pathDeterminan.java
File metadata and controls
42 lines (41 loc) · 845 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 Determinan
{
float a, b, c;
double D, x1, x2;
public Determinan(){}
public Determinan(float a, float b, float c)
{
this.a = a;
this.b = b;
this.c = c;
}
void hitungD()
{D= b*b-(4*a*c);}
void hitungX1X2()
{
if(D>0)
{
x1=(-b+Math.sqrt(D))/(2*a);
x2=(-b-Math.sqrt(D))/(2*a);
}
else if(D==0)
{
x1=x2=-b/(2*a);
}
else{
x1=(-b/(2*a))+(Math.sqrt(-D)/(2*a));
x2=(-b/(2*a))-(Math.sqrt(-D)/(2*a));
}
}
void cetakDeterminan()
{
hitungD();
hitungX1X2();
System.out.println("a : "+a);
System.out.println("b : "+b);
System.out.println("c : "+c);
System.out.println("D : "+D);
System.out.println("x1 : "+x1);
System.out.println("x2 : "+x2);
}
}