第二章第十六题(几何:六边形面积)(Geometry: area of a hexagon)

第二章第十六题(几何:六边形面积)(Geometry: area of a hexagon)

  • 2.16(几何:六边形面积)编写程序,提示用户输入六边形的边长,然后显示它的面积。计算六边形面积的公式是:
    面积 =在这里插入图片描述

    这里的s就是边长。下面是一个运行示例:

    Enter the length of the side : 5.5

    The area of the hexagon is 78.5918

    2.16Geometry: area of a hexagon) Write a program that prompts the user to enter the side of a hexagon and displays its area. The formula for computing the area of a hexagon is
    area = 在这里插入图片描述 .

    where s is the length of a side. Here is a sample run:

    Enter the length of the side : 5.5

    The area of the hexagon is 78.5918

  • 参考代码:

package chapter02;

import java.util.Scanner;

public class Code_16 {
    public static void main(String[] args) {
        double LengthHexagonSide,AreaHexagon;

        System.out.print("Enter the length of the side : ");
        Scanner LenSideInput = new Scanner(System.in);
        LengthHexagonSide = LenSideInput.nextDouble();

        AreaHexagon = 3 * Math.pow(3,0.5) / 2 * Math.pow(LengthHexagonSide,2);

        System.out.println("The area of the hexagon is " + AreaHexagon);

        LenSideInput.close();
    }
}

  • 结果显示:
Enter the length of the side : 5.5
The area of the hexagon is 78.59180539343781

Process finished with exit code 0

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值