forked from VenusTokyo/first-year-java-practicals
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComplex.java
More file actions
59 lines (41 loc) · 907 Bytes
/
Complex.java
File metadata and controls
59 lines (41 loc) · 907 Bytes
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
import java.io.*;
public class Complex
{
double real,img;
Complex()
{
real=0.0;
img=0.0;
}
Complex(double x, double y)
{
real=x;
img=y;
}
void addition(Complex a,Complex b)
{
real=b.real+a.real;
img=b.img+a.img;
System.out.print(toString());
}
void multiply(Complex a, Complex b)
{
real=a.real*b.real-a.img*b.img;
img=a.real*b.img+b.real*a.img;
System.out.print(toString());
}
public String toString()
{
return String.format(real+"+i"+img);
}
public static void main(String args[])
{
Complex c1=new Complex(4.2,3.2);
Complex c2=new Complex(2.2,6.2);
Complex c3=new Complex();
System.out.print("The addition of the 2 complex nos. is :");
c3.addition(c1, c2);
System.out.print("The multiplication of the 2 complex nos. is :");
c3.multiply(c1, c2);
}
}