Advertisement
Guest User

Complex

a guest
May 29th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.*;
  2. class Complex
  3. {
  4.  
  5. private int real;
  6. private int img;
  7.  
  8. void get()
  9. {
  10. System.out.println("Enter the complex number real and img");
  11. Scanner sc=new Scanner(System.in);
  12. real = sc.nextInt();
  13. img =sc.nextInt();
  14. }
  15.  
  16. void show()
  17. {
  18. if (img<0)
  19. System.out.println(real+"-"+img(-1)+"i");
  20. else
  21. System.out.println(real+"+"+img+"i");
  22. }
  23.  
  24. Complex(int x,int y)
  25. {
  26. real=x;
  27. img=y;
  28. }
  29.  
  30. Complex()
  31. {
  32. }
  33.  
  34. complex add(complex x)
  35. {
  36. Complex t= new Complex();
  37. t.real = real+x.real;
  38. t.img = img+x.img;
  39. return t;
  40. }
  41.  
  42. public static void main(String args[])
  43. {
  44. Complex c1,c2,c3;
  45. c1=new Complex(1,-1);
  46. c2=new Complex();
  47. c2.get();
  48. c3=new Complex();
  49. c3=c1.add(c2);
  50. c1.show();
  51. c2.show();
  52. c3.show();
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement