-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex.java
More file actions
47 lines (41 loc) · 1.36 KB
/
Copy pathComplex.java
File metadata and controls
47 lines (41 loc) · 1.36 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
import java.util.*;
class Complex {
int r1;
int i1;
Complex() {
}
void sum(Complex x, Complex y) {
r1 = x.r1 + y.r1;
i1 = x.i1 + y.i1;
System.out.println("The Sum of two Complex number is: " + r1 + "+" + i1 + "i");
}
void difference(Complex x, Complex y) {
r1 = x.r1 - y.r1;
i1 = x.i1 - y.i1;
System.out.println("The Difference of two Complex number is: " + r1 + "+" + i1 + "i");
}
void product(Complex x, Complex y) {
r1 = x.r1 * y.r1;
i1 = x.i1 * y.i1;
System.out.println("The Product of two Complex number is: " + r1 + "+" + i1 + "i");
}
}
class Calcomplex {
public static void main(String[] rds) {
Scanner sc = new Scanner(System.in);
Complex c1 = new Complex();
System.out.print("Enter Real part of First Number: ");
c1.r1 = sc.nextInt();
System.out.print("Enter Imaginary part of First Number: ");
c1.i1 = sc.nextInt();
Complex c2 = new Complex();
System.out.print("Enter Real part of Second Number: ");
c2.r1 = sc.nextInt();
System.out.print("Enter Imaginary part of Second Number: ");
c2.i1 = sc.nextInt();
Complex c3 = new Complex();
c3.sum(c1, c2);
c3.difference(c1, c2);
c3.product(c1, c2);
}
}