java中输出结果为NaN 是怎么回事?麻烦指教一下
classpoint{intX,Y;point(intx,inty){X=x;Y=y;System.out.println("坐标是"+X+","+Y);}intgetx...
class point
{int X ,Y;
point(int x,int y)
{ X=x;
Y=y;
System.out.println("坐标是 "+X+", "+Y);
}
int getx(){return X;}
int gety(){return Y;}
}
class circle
{
point p1;
static double r;
double area1,zhou1;
circle(int j){System.out.println("调用circle的构造函数");}
public double Area_c(double r1)
{
r=r1;
area1=3.14*r*r;
return area1;
}
public double zhouchang_c()
{
zhou1=3.14*r*2;
return zhou1;
}
}
class Rectangle
{
int p;
static int longth;
static int width;
int area2,zhou2;
public int Area_r(int l,int w)
{
longth=l;
width=w;
area2=longth*width;
return area2;
}
public int zhouchang_r()
{
zhou2=2*(longth + width);
return zhou2;
}
}
class Triangle
{ point p1,p2,p3;
double m,n,q,area,p,zhou3;
Triangle(int q){System.out.println("调用Triangle的构造函数");}
double Area_t(point p1,point p2,point p3)
{
m=Math.sqrt((p1.getx()-p2.getx())^2-(p1.gety()-p2.gety())^2);
n=Math.sqrt((p1.getx()-p3.getx())^2-(p1.gety()-p3.gety())^2);
q=Math.sqrt((p3.getx()-p2.getx())^2-(p3.gety()-p2.gety())^2);
p=(m+n+q)/2;
area=Math.sqrt(p*(p-m)*(p-n)*(p-q));
return area;
}
double zhouchang_t()
{
zhou3=m+n+q;
return zhou3;
}
}
public class KY4_4
{
public static void main(String []args)
{ point p1=new point(180,120);
point p2=new point(180,130);
point p3=new point(220,130);
circle c=new circle(1);
System.out.println("圆的面积是"+c.Area_c(15));
System.out.println("圆的周长是"+c.zhouchang_c());
Rectangle r=new Rectangle();
System.out.println("矩形的面积是"+r.Area_r(12,8));
System.out.println("矩形的周长是"+r.zhouchang_r());
Triangle t=new Triangle(2);
System.out.println("三角形的面积是"+t.Area_t(p1,p2,p3));
System.out.println("三角形的周长是"+t.zhouchang_t());
}
} 展开
{int X ,Y;
point(int x,int y)
{ X=x;
Y=y;
System.out.println("坐标是 "+X+", "+Y);
}
int getx(){return X;}
int gety(){return Y;}
}
class circle
{
point p1;
static double r;
double area1,zhou1;
circle(int j){System.out.println("调用circle的构造函数");}
public double Area_c(double r1)
{
r=r1;
area1=3.14*r*r;
return area1;
}
public double zhouchang_c()
{
zhou1=3.14*r*2;
return zhou1;
}
}
class Rectangle
{
int p;
static int longth;
static int width;
int area2,zhou2;
public int Area_r(int l,int w)
{
longth=l;
width=w;
area2=longth*width;
return area2;
}
public int zhouchang_r()
{
zhou2=2*(longth + width);
return zhou2;
}
}
class Triangle
{ point p1,p2,p3;
double m,n,q,area,p,zhou3;
Triangle(int q){System.out.println("调用Triangle的构造函数");}
double Area_t(point p1,point p2,point p3)
{
m=Math.sqrt((p1.getx()-p2.getx())^2-(p1.gety()-p2.gety())^2);
n=Math.sqrt((p1.getx()-p3.getx())^2-(p1.gety()-p3.gety())^2);
q=Math.sqrt((p3.getx()-p2.getx())^2-(p3.gety()-p2.gety())^2);
p=(m+n+q)/2;
area=Math.sqrt(p*(p-m)*(p-n)*(p-q));
return area;
}
double zhouchang_t()
{
zhou3=m+n+q;
return zhou3;
}
}
public class KY4_4
{
public static void main(String []args)
{ point p1=new point(180,120);
point p2=new point(180,130);
point p3=new point(220,130);
circle c=new circle(1);
System.out.println("圆的面积是"+c.Area_c(15));
System.out.println("圆的周长是"+c.zhouchang_c());
Rectangle r=new Rectangle();
System.out.println("矩形的面积是"+r.Area_r(12,8));
System.out.println("矩形的周长是"+r.zhouchang_r());
Triangle t=new Triangle(2);
System.out.println("三角形的面积是"+t.Area_t(p1,p2,p3));
System.out.println("三角形的周长是"+t.zhouchang_t());
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询