JavaBean+JSP复数运算的问题
问题是:1.为什么加的结果不是复数相加而是两个复数的实部和虚部作为普通数字相加的结果
2.为什么我加的if-else语句没有起作用呢? 嗯……它自己又好了……{:10_247:}
不过除还是有点问题,div()效果还是不行package beans;
public class Div {
private int sba;
private int xba;
private int sbb;
private int xbb;
public int getSba() {
return sba;
}
public void setSba(int sba) {
this.sba = sba;
}
public int getXba() {
return xba;
}
public void setXba(int xba) {
this.xba = xba;
}
public int getSbb() {
return sbb;
}
public void setSbb(int sbb) {
this.sbb = sbb;
}
public int getXbb() {
return xbb;
}
public void setXbb(int xbb) {
this.xbb = xbb;
}
public String div(){
String rs = null;//sba:a的实部,xba:a的虚部
if((float)((xba*sbb - sba*xbb)/(sbb*sbb + xbb*xbb)) > 0)
rs = ((float)(sba*sbb + xba*xbb)/(sbb*sbb + xbb*xbb)) + "+" + ((float)(xba*sbb - sba*xbb)/(sbb*sbb + xbb*xbb)) + "i";
else if((float)((xba*sbb - sba*xbb)/(sbb*sbb + xbb*xbb)) < 0)
rs = ((float)(sba*sbb + xba*xbb)/(sbb*sbb + xbb*xbb)) + "" + ((float)(xba*sbb - sba*xbb)/(sbb*sbb + xbb*xbb)) + "i";
else
rs = ((float)(sba*sbb + xba*xbb)/(sbb*sbb + xbb*xbb)) + "";
//(a+bi)/(c+di)=(ac+bd)/(c2+d2) +((bc-ad)/(c2+d2))i
return rs;
}
}
{:9_239:} 呃,这个有点复杂,我去百度查查资料{:10_245:}
页:
[1]