此方程两个虚根为:NaNi,NaNi这是怎么回事???(编译没问题 运行出上面的语句)class Equation{
private float a,b,c;
static double z,p;
public Equation(){}
public Equation(float a,float b,float c){
this.a=a;
this.b=b;
this.c=c;
}
public void setA(float a){
this.a=a;
}
public float getA(){
return a;
}
public void setB(float b){
this.b=b;
}
public float getB(){
return b;
}
public void setC(float c){
this.c=c;
}
public float getC(){
return c;
}
public void Math(){
p=b*b-4*a*c;
z=Math.sqrt(p);
}
private boolean panduan(){
return z!=0;
}
private boolean panduan2(){
return z>0;
}
public void showEquation(){
double f,g;
f=-b+z;g=-b-z;
if(panduan()){
if(panduan2()){
System.out.println("此方程两个实根为:"+f/(2*a)+","+g/(2*a));
}else{
System.out.println("此方程两个虚根为:"+g/(2*a)+"i,"+f/(2*a)+"i");
}
}else{
System.out.println("此方程两个相同的实根为:"+(-b+z)/(2*a));
}
}
}
class TestEquation{
public static void main(String args[]){
Equation a1 = new Equation(5.0f,3.0f,2.0f);
a1.Math();
a1.showEquation();
}
}
添加回答
举报
0/150
提交
取消