java 既然出現double型別×2的n次方的時候計算結果出現偏差!
程式碼如下:
package Com.Aftvc.tsing;
public class example {
/**
* @param args
*/
public static void main(String[] args) {
//EXE p = new EXE(8);
//p.decrease();
//p.add();
//p.mult();
Figure tri = new Triangle(3,4,5);
System.out.println("此三角形的周長是:"+tri.GetGirth());
System.out.println("此三角形的面積是:"+tri.GetArea());
Figure cir = new Circle(5);
System.out.println("此圓的周長是:"+cir.GetGirth());
System.out.println("此圓的面積是:"+cir.GetArea());
Figure tra = new Trapezoid(3,9,4,5,5);
System.out.println("此梯形的周長是:"+tra.GetGirth());
System.out.println("此梯形面積是:"+tra.GetArea());
}
}
package Com.Aftvc.tsing;
public class Circle implements Figure{
double r;
public Circle(double r1){
r=r1;
}
public double GetArea(){
return PI*r*r*2;
}
public double GetGirth(){
return PI*r*2;//如果*3結果47.1 *4結果很長!!我測試了1,2,3,4,5,6,7,8,9,10,11,12,16只要是2的n次方就出現很長的結果。
}
}
此三角形的周長是:12.0
此三角形的面積是:6.0
此圓的周長是:31.400000000000002
此圓的面積是:157.0
此梯形的周長是:22.0
此梯形面積是:24.0
return PI*r*2;