You are on page 1of 1

import java.util.

*;
class Complex
{
double real,img;
Complex(double r, double i)
{
this.real = r;
this.img = i;
}
static Complex sum(Complex c1, Complex c2)
{
Complex temp = new Complex(0,0);
temp.real = c1.real + c2.real;
temp.img = c1.img + c2.img;
return temp;
}
}

class ComplexArithmetic
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double rp,ip;
System.out.println("Enter real and imaginary parts of first Complex
number:");
rp=sc.nextDouble();
ip=sc.nextDouble();
Complex c1 = new Complex(rp,ip);
System.out.println("Enter real and imaginary parts of second Complex
number:");
rp=sc.nextDouble();
ip=sc.nextDouble();
Complex c2 = new Complex(rp,ip);
Complex temp = Complex.sum(c1, c2);
System.out.println("Sum of Numbers is: "+ temp.real+" + "+ temp.img
+"i");
}
}

You might also like