publicclassComplex{privateintx;privateinty;publicintgetX{returnx;}publicintgetY{returny;}publicvoidsetXintx{this.x=x;}publicvoidsetYinty{this.y=y;}publicComplex{x=0;y=0;}publicComplexinti,intj{x=i;y=j;}publicvoidshowComp{ifx==0&&y==0{System.out.println"0";return;}Strings1=""+x==0?"":x;Strings2="";ify>0s2="+"+y==1?"":y+"i";ify<0s2=y==-1?"-":y+"i";System.out.printlns1+s2;}publicComplexaddCompComplexc1,Complexc2{returnnewComplexc1.getX+c2.getX,c1.getY+c2.getY;}publicComplexsubCompComplexc1,Complexc2{returnnewComplexc1.getX-c2.getX,c1.getY-c2.getY;}publicComplexmultiCompComplexc1,Complexc2{returnnewComplexc1.getX*c2.getX-c1.getY*c2.getY,c1.getX*c2.getY+c2.getX*c1.getY;}publicbooleanequalCompComplexC1,ComplexC2{returnc1.getX==c2.getX&&c1.getY==c2.getY;}}纯手打,八九不离十。
黄盛福2019-12-21 23:56:55