为什么圆的周长算出来的小数点的位数不对
package com.yong; public abstract class Shape { public abstract void Perimeter(); public abstract void Area(); }
package com.yong;
public class Rectangle extends Shape {
double a=10;
double b=20;
@Override
public void Perimeter() {
double c=(a+b)*2;
System.out.println("长方形的周长为:"+c);
}
@Override
public void Area() {
double s=a*b;
System.out.println("长方形的面积为:"+s);
}
}
package com.yong;
public class Circle extends Shape {
final double PI=3.14;
double r=10.0;
@Override
public void Perimeter() {
double c=2*PI*r;
System.out.println("圆的周长为:"+c);
}
@Override
public void Area() {
double s=PI*r*r;
System.out.println("圆的面积为:"+s);
}
}
package com.yong;
public class Test {
public static void main(String[] args) {
Shape sh1=new Rectangle();
sh1.Area();
sh1.Perimeter();
Shape sh2=new Circle();
sh2.Perimeter();
sh2.Area();
}
}
长方形的面积为:200.0
长方形的周长为:60.0
圆的周长为:62.800000000000004
圆的面积为:314.0