-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPracticeQs.java
More file actions
47 lines (36 loc) · 1.01 KB
/
PracticeQs.java
File metadata and controls
47 lines (36 loc) · 1.01 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
public class PracticeQs {
public static void main(String args[]) {
Complex obj1 = new Complex(5, 4);
Complex obj2 = new Complex(3, 2);
Complex sum = obj1.add(obj2);
sum.print();
}
}
class Complex {
int real;
int imag;
int realres;
int imagres;
Complex(int real, int imag) {
this.real = real;
this.imag = imag;
}
Complex add(Complex num) {
realres = this.real + num.real;
imagres = this.imag + num.imag;
return new Complex(realres, imagres);
}
Complex sub(Complex num) {
realres = this.real - num.real;
imagres = this.imag - num.imag;
return new Complex(realres, imagres);
}
Complex mul(Complex num) {
realres = (this.real * num.real) - (this.imag * num.imag);
imagres = (this.real * num.real) + (this.imag * num.imag);
return new Complex(realres, imagres);
}
void print() {
System.out.println(this.real + "+" + this.imag + "i");
}
}