import java.util.*;
class Complex{
    int a,b;
    Complex(int m,int n)
    {
        a=m;
        b=n;
    }
    Complex(Complex t)
    {
        a=t.a;
        b=t.b;
    }
    Complex Add(Complex r)
    {
        Complex com=new Complex(a+r.a,b+r.b);
        return com;
    }
    Complex Sub(Complex r)
    {
        Complex com=new Complex(a-r.a,b-r.b);
        return com;
    }
    void Print()
    {
        if(a==0&&b==0)
            System.out.println(0);
        else
            System.out.println(a+"+"+b+"i");
    } 
}
public class Main{
    public static void main(String[] args) {
        int m,n;    //第一个数的实部和虚部
        int p,q;    //第二个数的实部和虚部
        Scanner scanner =new Scanner(System.in);
        m=Integer.parseInt(scanner.next());
        n=Integer.parseInt(scanner.next());
        p=Integer.parseInt(scanner.next());
        q=Integer.parseInt(scanner.next());
        Complex t =new Complex(m,n);
        Complex s =new Complex(t);
        Complex r=new Complex(p,q);
        (s.Add(r)).Print();
        (s.Sub(r)).Print();
    }
}
0
Posted in Java

Leave a Comment:

电子邮件地址不会被公开。