-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQB 694.java
46 lines (32 loc) · 869 Bytes
/
QB 694.java
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
//QB 694
import java.util.*;
class complex {
int real, img;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter real number 1 & 2 : ");
int a = sc.nextInt();
int b = sc.nextInt();
complex c1 = new complex(a, b);
System.out.println("Enter imaginary number 1 & 2 : ");
int p = sc.nextInt();
int q = sc.nextInt();
complex c2 = new complex(p, q);
complex c3 = new complex();
c3.add(c1, c2);
c3.display();
}
complex(int x, int y) {
real = x;
img = y;
}
complex() {
}
void add(complex p1, complex p2) {
real = p1.real + p2.real;
img = p1.img + p2.img;
}
void display() {
System.out.println("ans=(" + real + "," + img + ")");
}
}