-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddComplexNo.java
More file actions
45 lines (33 loc) · 897 Bytes
/
AddComplexNo.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
public class AddComplexNo {
public static void main(String[] args) {
ComplexNo C1 = new ComplexNo();
C1.set(3f, 2f);
System.out.println("Complex number 1 : " + C1.real + " + i" + C1.imaginary);
ComplexNo C2 = new ComplexNo();
C2.set(6f, 5f);
System.out.println("Complex number 2 : " + C2.real + " + i" + C2.imaginary);
ComplexNo C3 = new ComplexNo();
C3 = C3.sum(C1, C2);
C3.disp();
}
}
class ComplexNo {
ComplexNo t;
float real, imaginary;
ComplexNo() {
}
void set(float tempReal, float tempImaginary) {
real = tempReal;
imaginary = tempImaginary;
}
ComplexNo sum(ComplexNo C1, ComplexNo C2) {
ComplexNo temp = new ComplexNo();
temp.real = C1.real + C2.real;
temp.imaginary = C1.imaginary + C2.imaginary;
this.t = temp;
return temp;
}
void disp() {
System.out.println("Sum of complex number : " + real + " " + "+ " + imaginary + "i");
}
}