第一章第八题(圆的面积和周长)(Area and perimeter of a circle)

第一章第八题(圆的面积和周长)(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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值