Sunday, 17 July 2011

Write a program of addition of complex number

import java.io.*;
class complex25
{
int real;
int img;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the real and imaginary part");
real=Integer.parseInt(br.readLine());
img=Integer.parseInt(br.readLine());
}
public void output()
{
System.out.println(real+"+"+img+"i");
}
public complex25 sum(complex25 c1,complex25 c2)
{
complex25 c3=new complex25();
c3.real=c1.real+c2.real;
c3.img=c1.img+c2.img;
return c3;
}
}
class complex25main
{
public static void main(String[] arg)
throws IOException
{
complex25 c1=new complex25();
complex25 c2=new complex25();
complex25 c3=new complex25();
c1.input();
c2.input();
System.out.println("first complex no is=");
c1.output();
System.out.println("second complex no is=");
c2.output();
c3=c3.sum(c1,c2);
System.out.println("result is=");
c3.output();
}}

No comments:

Post a Comment

 

About The Author


I am a B.Tech Computer Science Student. I love Programming and blogging. I am Oracle certified Java Professional. Read More
Indian Blogger

Teachers Jobs

Footer 3

Twitter Facebook RSS YouTube Google
​

All Rights Reserved ©Sun Java Masters 2013