Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- public class complex{
- public static void main(String Args[])
- {
- Scanner sc = new Scanner(System.in);
- complex_add obj = new complex_add();
- System.out.print("Enter real part of 1st number : ");
- int r1 = sc.nextInt();
- System.out.print("Enter real part of 2nd number : ");
- int r2 = sc.nextInt();
- System.out.print("Enter img part of 1st number : ");
- int i1 = sc.nextInt();
- System.out.print("Enter img part of 2nd number : ");
- int i2 = sc.nextInt();
- obj.set_i1(i1);
- obj.set_i2(i2);
- obj.set_r1(r1);
- obj.set_r2(r2);
- obj.add();
- System.out.println(obj);
- System.out.println(obj.getClass());
- }
- }
- class complex_add {
- private int r1, r2, i1, i2;
- complex_add()
- {
- System.out.println("Constructor called");
- r1 = 0;
- r2 = 0;
- i1 = 0;
- i2 = 0;
- }
- void set_r1(int v)
- {
- r1 = v;
- }
- void set_r2(int v)
- {
- r2 = v;
- }
- void set_i1(int v)
- {
- i1 = v;
- }
- void set_i2(int v)
- {
- i2 = v;
- }
- void add()
- {
- System.out.println("\nThe sum is = " + (r1+r2) + "+" + (i1+i2) + "i");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement