Q:

(Geometry: 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

0

(Geometry: 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

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

Output:

Enter the side: 5.5
The area of the hexagon is 78.5895

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*
(Geometry: area of a hexagon) Write a program that prompts the user to enter the
side of a hexagon and displays its area.
*/
import java.util.Scanner;

public class Exercise_02_16 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		// Prompt the user to enter the side of a hexagon
		System.out.print("Enter the side: ");
		double side = input.nextDouble();

		// Compute the area of the hexagon
		double area = ((3 * Math.pow(3, 0.5)) / 2) * Math.pow(side, 2);

		// Display result
		System.out.println("The area of the hexagon is " + area); 
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now