- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddComplexNo.java
More file actions
Latest commit
45 lines (33 loc) · 897 Bytes
/
Copy pathAddComplexNo.java
File metadata and controls
45 lines (33 loc) · 897 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
43
44
45
publicclassAddComplexNo {
publicstaticvoidmain(String[] args) {
ComplexNoC1 = newComplexNo();
C1.set(3f, 2f);
System.out.println("Complex number 1 : " + C1.real + " + i" + C1.imaginary);
ComplexNoC2 = newComplexNo();
C2.set(6f, 5f);
System.out.println("Complex number 2 : " + C2.real + " + i" + C2.imaginary);
ComplexNoC3 = newComplexNo();
C3 = C3.sum(C1, C2);
C3.disp();
}
}
classComplexNo {
ComplexNot;
floatreal, imaginary;
ComplexNo() {
}
voidset(floattempReal, floattempImaginary) {
real = tempReal;
imaginary = tempImaginary;
}
ComplexNosum(ComplexNoC1, ComplexNoC2) {
ComplexNotemp = newComplexNo();
temp.real = C1.real + C2.real;
temp.imaginary = C1.imaginary + C2.imaginary;
this.t = temp;
returntemp;
}
voiddisp() {
System.out.println("Sum of complex number : " + real + " " + "+ " + imaginary + "i");
}
}