第一章第八题(圆的面积和周长)(Area and perimeter of a circle)
- 1.8(圆的面积和周长)编写程序,使用以下公式计算并显示半径为5.5的圆的面积和周长:
1.8 (Area and perimeter of a circle) Write a program that displays the area and perimeter of a circle that has a radius of 5.5 using the following formula:
-
参考代码:
-
方法一:
package chapter01; public class Code_08 { public static void main(String[] args){ zhouChang(5.5); mianJi(5.5); } static void zhouChang(double radius){ System.out.println(2*radius*Math.PI); } static void mianJi(double radius){ System.out.println(Math.PI*radius*radius); } }
-
方法二:
package chapter01; public class Code_08another { public static void main(String[] args) { double the_radius_of_circle = 5.5,PI = 3.1415926; double the_perimeter_of_circle = 2.0 * the_radius_of_circle * PI; double the_area_of_circle = the_radius_of_circle * the_radius_of_circle * PI; System.out.println("the perimeter of the circle : " + the_perimeter_of_circle); System.out.println("the area of the circle : " + the_area_of_circle); } }
-
-
结果显示:
34.55751918948772
95.03317777109123
Process finished with exit code 0