计算六边形面积的公式是:面积 = S * S / 2
这里的S就是边长。
下面是一个运算示例:
Enter the side: 5.5
The area of the hexagon is 78.5918
package Second;
import java.util.Scanner;
public class Code16 {
public static void main(String[] args) {
System.out.print("Enter the side: ");
Scanner input = new Scanner(System.in);
double side = input.nextDouble();
double area = 3 * Math.pow(3, 0.5) * Math.pow(side,2) / 2;
System.out.println("The area of the hexagon is:" + area);
}
}
输出
Enter the side: 5.5 The area of the hexagon is:78.59180539343781