-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab_5_5.java
55 lines (36 loc) · 1.28 KB
/
Lab_5_5.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
47
48
49
50
51
52
53
54
55
import java.util.*;
class Complex {
int realPart1;
int imgPart1;
double realPart2;
double imgPart2;
public Complex(int realPart1, int imgPart1) {
this.imgPart1=imgPart1;
this.realPart1 = realPart1;
}
public Complex(double realPart2, double imgPart2) {
this.realPart2 = realPart2;
this.imgPart2 = imgPart2;
}
public double add() {
this.realPart2 += this.realPart1;
this.imgPart2 += this.imgPart1 ;
}
}
public class Lab_5_5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter ther real part of first number :");
int realPart1 = sc.nextInt();
System.out.println("Enter the imaginary part of first number: ");
int imgPart1 = sc.nextInt();
System.out.println("Enter the realpart second number :");
Double realPart2 = sc.nextDouble();
System.out.println("Enter the imaginary part second number");
Double imgPart2 = sc.nextDouble();
Complex c1 = new Complex(realPart1, imgPart1);
Complex c2 = new Complex(realPart2, imgPart2);
Complex res= c2.add(c1);
System.out.println(" " + res.realPart1+ " " + res.imgPart1 + "i");
}
}