Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Complex
- {
- private int real;
- private int img;
- void get()
- {
- System.out.println("Enter the complex number real and img");
- Scanner sc=new Scanner(System.in);
- real = sc.nextInt();
- img =sc.nextInt();
- }
- void show()
- {
- if (img<0)
- System.out.println(real+"-"+img(-1)+"i");
- else
- System.out.println(real+"+"+img+"i");
- }
- Complex(int x,int y)
- {
- real=x;
- img=y;
- }
- Complex()
- {
- }
- complex add(complex x)
- {
- Complex t= new Complex();
- t.real = real+x.real;
- t.img = img+x.img;
- return t;
- }
- public static void main(String args[])
- {
- Complex c1,c2,c3;
- c1=new Complex(1,-1);
- c2=new Complex();
- c2.get();
- c3=new Complex();
- c3=c1.add(c2);
- c1.show();
- c2.show();
- c3.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement