forked from mayankgb2/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_number.java
More file actions
31 lines (25 loc) · 781 Bytes
/
complex_number.java
File metadata and controls
31 lines (25 loc) · 781 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
#https://www.facebook.com/shruti.buchha.7/posts/3341900509242443
#subscribed by shruti buchha
import java.util.*;
import java.lang.*;
import java.io.*;
public class ComplexNumber{
double real, img;
ComplexNumber(double r, double i){
this.real = r;
this.img = i;
}
public static ComplexNumber sum(ComplexNumber c1, ComplexNumber c2)
{
ComplexNumber temp = new ComplexNumber(0, 0);
temp.real = c1.real + c2.real;
temp.img = c1.img + c2.img;
return temp;
}
public static void main(String args[]) {
ComplexNumber c1 = new ComplexNumber(5.5, 4);
ComplexNumber c2 = new ComplexNumber(1.2, 3.5);
ComplexNumber temp = sum(c1, c2);
System.out.printf("Sum is: "+ temp.real+" + "+ temp.img +"i");
}
}