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
}
}
运行结果: