The problem
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 = 3 Sqrt 3 / 2 s ^ 2
where s is the length of a side. Here is a sample run:
Enter the side: 5.5
The area of the hexagon is 78.5895
Breaking it down
public static void main(String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the side: ");
double side = input.nextDouble();
input.close();
double area = areaOfHexagon(side);
System.out.println("The area of the hexagon is " + area);
}
private static double areaOfHexagon(double side) {
double area = 3 * 1.732 * side * side / 2;
return area;
}
Output
Enter the side: 10
The area of the hexagon is 259.79999999999995