It was an exercise after class. Write down the code here.
Import Java.util.Scanner;
public class Complex {
public int a=0;
public int b=0;
Public Complex () {
System.out.println ("Please enter a plural");
Scanner s=new Scanner (system.in);
String T=s.next ();
This.a=getx (t);
This.b=gety (t);
}
public int GetX (String x) {//Get the previous integer of the input data
String m;
M=x.split ("[+]") [0];
Return Integer.parseint (m);
}
public int GetY (String y)//Gets the last integer of the input data
{
String m;
M=y.split ("[+]") [1].replace ("I", "");
Return Integer.parseint (m);
}
public void Add ()
{
System.out.println ("addition:");
System.out.println ("Please enter a plural");
Scanner s=new Scanner (system.in);
String T=s.next ();
This.a=a+getx (t);
This.b=b+gety (t);
System.out.println ("complex number operation result is:" +a+ "+" +b+ "I");
}
public void subtraction ()
{
System.out.println ("subtraction:");
System.out.println ("Please enter a plural");
Scanner s=new Scanner (system.in);
String T=s.next ();
This.a=a-getx (t);
This.b=b-gety (t);
System.out.println ("complex number operation result is:" +a+ "+" +b+ "I");
}
public void multiplication () {
System.out.println ("multiplication:");
System.out.println ("Please enter a plural");
Scanner s=new Scanner (system.in);
String T=s.next ();
This.a=a*getx (t);
This.b=b*gety (t);
System.out.println ("complex number operation result is:" +a+ "+" +b+ "I");
}
public static void Main (String args[]) {
Complex c=new complex ();
C.add ();
C.subtraction ();
C.multiplication ();
}
}
After the operation, it is found that because the operation process is considered simple, the value of a,b is reused, so the first input cannot be the default value, the equivalent of subtraction and multiplication is to compute the result of addition.