为什么这个输出时那个周长的结果会是错误的,例如输入为10,长度输出为62.800000004
public class Point{
double x,y;
Point(){x=0; y=0;}
Point(double x,double y){
this.x=x; this.y=y;
}
}
class Circle extends Point{
double radius;
Circle(){
radius=0;
}
Circle(double a,double b,double radius){
super(a,b);
this.radius=radius;
}
void printArea(){
System.out.println("圆的面积为:"+3.14*radius*radius);
}
void printCircu(){
System.out.println("圆的周长为:"+radius*2*3.14);
}
void show(){
System.out.println("圆心的坐标为:("+x+","+y+")");
}
}
public class CircleTest{
public static void main(String args[]){
Circle c1=new Circle(5,7,10);
c1.printArea();
c1.printCircu();
c1.show();
}
}
------解决方案--------------------double数据类型引起的。自己格式化一下显示保留两位小数就没问题了。