In Java, the calculation result is biased when the power of the Double Type X 2 is N!
CodeAs follows:
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 ("the circumference of this triangle is:" + tri. getgirth ());
System. Out. println ("the Triangle Area is:" + tri. getarea ());
Figure CIR = new circle (5 );
System. Out. println ("the circumference of this circle is:" + CIR. getgirth ());
System. Out. println ("the area of this circle is:" + CIR. getarea ());
Figure tra = new trapezoid (3,9, 4,5, 5 );
System. Out. println ("the circumference of this trapezoid is:" + tra. getgirth ());
System. Out. println ("this trapezoid area is:" + tra. getarea ());
}
}
Package com. aftvc. Tsing;
public class circle implements figure {
double r;
Public circle (double R1) {
r = R1;
}< br> Public double getarea () {
return pI * r * 2;
}< br> Public double getgirth () {
return pI * r * 2; // If * 3 Results 47.1*4 results are very long !! I tested 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16. As long as it is 2, The Npower shows a long result.
}< BR >}< br> the circumference of the triangle is: 12.0
the area of the triangle is: 6.0
the circumference of the circle is: 31.400000000000002
the area of the circle is: 157.0
the circumference of the trapezoid is: 22.0
the area of the trapezoid is: 24.0
return pI * r * 2;