-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacomplexClass.java
More file actions
65 lines (53 loc) · 1.24 KB
/
acomplexClass.java
File metadata and controls
65 lines (53 loc) · 1.24 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
class complex
{
private float real, imag;
public complex()
{
}
public complex(float r , float i)
{
real = r;
imag = i;
}
public void getData()
{
float r ,i ;
Scanner s = new Scanner(System.in);
System.out.println("enter real and imaginary part: ");
r = s.nextFloat();
i = s.nextFloat();
real = r;
imag = i;
}
public void setData(float r, float i)
{
real = r;
imag = i;
}
public void displayData()
{
System.out.println("real = "+real);
System.out.println("imag = "+imag);
}
public complex addcomplex(complex y)
{
complex t = new complex();
t.real = real * y.real - imag * y.imag;
t.imag = real * y.imag + y.real * imag;
return t;
}
}
public class acomplexClass {
public static void main(String arg[])
{
complex c1, c2, c3 ;
c1 = new complex();
c1.setData(2.0f,2.0f);
c2 = new complex();
c3 = new complex();
c3= c1.addcomplex(c2);
System.out.println("Complex c3");
c3.displayData();
}
}