最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

java实现复数运算

IT圈 admin 50浏览 0评论

2024年3月21日发(作者:卫泉)

public class Complex {

int shibu;

int xubu;

void setShibuAndXubu(int shibu,int xubu){

=shibu;

=xubu;

}

int getShibu(){

return shibu;

}

int getXubu(){

return xubu;

}

Complex add(Complex r){

int a=bu();

int b=u();

int newShibu=a+shibu;

int newXubu=b+xubu;

Complex result=new Complex();

buAndXubu( newShibu, newXubu);

return result;

}

Complex sub(Complex r){

int a=bu();

int b=u();

int newShibu=shibu-a;

int newXubu=xubu-b;

Complex result=new Complex();

buAndXubu( newShibu, newXubu);

return result;

}

Complex muti(Complex r){

int a=bu();

int b=u();

int newShibu=a*shibu-b*xubu;

int newXubu=a*xubu+b*shibu;

Complex result=new Complex();

buAndXubu( newShibu, newXubu);

return result;

}

}

public class ComplexUser {

/**

* @param args

*/

public static void main(String[] args) {

Complex r1=new Complex();

Complex r2=new Complex();

buAndXubu(6,5);

buAndXubu(3,2);

Complex result=(r2);

int resultshibu=bu();

int resultxubu=u();

System.

out

.printf("n%d+%di",resultshibu,resultxubu);

result=(r2);

resultshibu=bu();

resultxubu=u();

System.

out

.printf("n%d+%di",resultshibu,resultxubu);

result=(r2);

resultshibu=bu();

resultxubu=u();

System.

out

.printf("n%d+%di",resultshibu,resultxubu);

// TODO Auto-generated method stub

}

}

运行结果:

2024年3月21日发(作者:卫泉)

public class Complex {

int shibu;

int xubu;

void setShibuAndXubu(int shibu,int xubu){

=shibu;

=xubu;

}

int getShibu(){

return shibu;

}

int getXubu(){

return xubu;

}

Complex add(Complex r){

int a=bu();

int b=u();

int newShibu=a+shibu;

int newXubu=b+xubu;

Complex result=new Complex();

buAndXubu( newShibu, newXubu);

return result;

}

Complex sub(Complex r){

int a=bu();

int b=u();

int newShibu=shibu-a;

int newXubu=xubu-b;

Complex result=new Complex();

buAndXubu( newShibu, newXubu);

return result;

}

Complex muti(Complex r){

int a=bu();

int b=u();

int newShibu=a*shibu-b*xubu;

int newXubu=a*xubu+b*shibu;

Complex result=new Complex();

buAndXubu( newShibu, newXubu);

return result;

}

}

public class ComplexUser {

/**

* @param args

*/

public static void main(String[] args) {

Complex r1=new Complex();

Complex r2=new Complex();

buAndXubu(6,5);

buAndXubu(3,2);

Complex result=(r2);

int resultshibu=bu();

int resultxubu=u();

System.

out

.printf("n%d+%di",resultshibu,resultxubu);

result=(r2);

resultshibu=bu();

resultxubu=u();

System.

out

.printf("n%d+%di",resultshibu,resultxubu);

result=(r2);

resultshibu=bu();

resultxubu=u();

System.

out

.printf("n%d+%di",resultshibu,resultxubu);

// TODO Auto-generated method stub

}

}

运行结果:

发布评论

评论列表 (0)

  1. 暂无评论