import
java.util.Scanner;
class complex
{
float x,y;
complex()
{
x=0;
y=0;
}
complex(float
r,float i)
{
x=r;
y=i;
}
void show()
{
System.out.println("Sum
is "+x+"+i"+y);
}
void
sum(complex c1,complex c2)
{
x=c1.x+c2.x;
y=c1.y+c2.y;
}
}
class ComplexEx
{
public static
void main(String args[])
{
float x,y;
Scanner s=new
Scanner(System.in);
System.out.println("Enter
real and imaginary parts of first complex number:");
x=s.nextFloat();
y=s.nextFloat();
complex a=new
complex(x,y);
System.out.println("Enter
real and imaginary parts of second complex number:");
x=s.nextFloat();
y=s.nextFloat();
complex b=new
complex(x,y);
complex c=new
complex();
c.sum(a,b);
c.show();
}
}
OUTPUT:
C:\Program
Files\Java\jdk1.7.0\bin>java ComplexEx
Enter real and
imaginary parts of first complex number:
1 4
Enter real and
imaginary parts of second complex number:
5 6
Sum is
6.0+i10.0
No comments:
Post a Comment