import java.io.*;
class Complex
{
static double x1,y1,x2,y2;
static int count=0;
Complex()
{
}
Complex(double i,double j)
{
if(count==0)
{
x1=i;
y1=j;
}
else
{
x2=i;
y2=j;
}
}
public static void Add()
{
System.out.println("Sum of two complex numbers:"+(x1+x2)+"+i"+(y1+y2));
}
public static void Subtract()
{
System.out.println("Sum of two complex numbers:"+(x1-x2)+"+i"+(y1-y2));
}
public static void Multiply()
{
System.out.println("After Multiplication the complex number is:"+(x1*x2-y1*y2)+"+i"+(x1*y2+x2*y1));
}
public static void main(String args[])
{
double p1=0.0,p2=0.0,q1=0.0,q2=0.0;
BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the real and imaginary part of first complex number respectively:");
try
{
p1=Double.parseDouble(bf.readLine());
q1=Double.parseDouble(bf.readLine());
Complex C1=new Complex(p1,q1);
count=1;
System.out.println("Enter the real and imaginary part of second complex number respectively:");
p2=Double.parseDouble(bf.readLine());
q2=Double.parseDouble(bf.readLine());
}
catch(Exception e)
{
e.printStackTrace();
}
Complex C2=new Complex(p2,q2);
Complex C3=new Complex();
Complex.Add();
Complex.Subtract();
Complex.Multiply();
}
}
class Complex
{
static double x1,y1,x2,y2;
static int count=0;
Complex()
{
}
Complex(double i,double j)
{
if(count==0)
{
x1=i;
y1=j;
}
else
{
x2=i;
y2=j;
}
}
public static void Add()
{
System.out.println("Sum of two complex numbers:"+(x1+x2)+"+i"+(y1+y2));
}
public static void Subtract()
{
System.out.println("Sum of two complex numbers:"+(x1-x2)+"+i"+(y1-y2));
}
public static void Multiply()
{
System.out.println("After Multiplication the complex number is:"+(x1*x2-y1*y2)+"+i"+(x1*y2+x2*y1));
}
public static void main(String args[])
{
double p1=0.0,p2=0.0,q1=0.0,q2=0.0;
BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the real and imaginary part of first complex number respectively:");
try
{
p1=Double.parseDouble(bf.readLine());
q1=Double.parseDouble(bf.readLine());
Complex C1=new Complex(p1,q1);
count=1;
System.out.println("Enter the real and imaginary part of second complex number respectively:");
p2=Double.parseDouble(bf.readLine());
q2=Double.parseDouble(bf.readLine());
}
catch(Exception e)
{
e.printStackTrace();
}
Complex C2=new Complex(p2,q2);
Complex C3=new Complex();
Complex.Add();
Complex.Subtract();
Complex.Multiply();
}
}
Comments
Post a Comment