-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcomplexNumberTest.java
More file actions
52 lines (42 loc) · 1.17 KB
/
complexNumberTest.java
File metadata and controls
52 lines (42 loc) · 1.17 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
48
49
50
51
52
class complexnumber {
private double real;
private double img;
void inputA(double a1) {
real = a1;
}
void inputB(double b1) {
img = b1;
}
double getA() {
return real;
}
double getB() {
return img;
}
void addComplexA(complexnumber a, complexnumber b) {
real = a.real + b.real;
img = a.img + b.img;
}
void subsComplexB(complexnumber a,complexnumber b) {
real=a.real-b.real;
img=a.img-b.img;
}
}
public class complexNumberTest {
public static void main(String args[]) {
complexnumber c1 = new complexnumber();
complexnumber c2 = new complexnumber();
c1.inputA(2.0);
c2.inputA(3.0);
c1.inputB(-4.0);
c2.inputB(-5.0);
complexnumber ans=new complexnumber();
ans.addComplexA(c1, c2);
if(ans.getB()>=0)
System.out.println(ans.getA()+"+"+ans.getB()+"i");
else
System.out.println(ans.getA()+" "+ans.getB()+"i");
ans.subsComplexB(c1, c2);
System.out.println(ans.getA()+"+"+ans.getB()+"i");
}
}