(Geometry: area of a hexagon) The area of a hexagon can be computed using the following formula (s is the length of a side):Write a program that prompts the user to enter the side of a hexagon and displays its area.
Here is a sample run:
Enter the side: 5.5
The area of the hexagon is 78.59
Here is a sample run:
Enter the side: 5.5
The area of the hexagon is 78.59
import java.util.Scanner; public class ProgrammingEx4_4 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the side:"); double s = input.nextDouble(); double area = 6 * Math.pow(s, 2) / (4 * Math.tan(Math.PI / 6)); area = Math.round(area * 100) / 100.0; System.out.println("The area of the hexagon is " + area); } }
No comments:
Post a Comment