Q:

Write a Java program to compute the area of a hexagon

0

Write a Java program to compute the area of a hexagon
Area of a hexagon = (6 * s^2)/(4*tan(π/6))
where s is the length of a side


Input Data:
Input the length of a side of the hexagon: 6
Expected Output

The area of the hexagon is: 93.53074360871938

All Answers

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

import java.util.Scanner;
public class Exercise34 {
      public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Input the length of a side of the hexagon: ");
        double s = input.nextDouble();
        System.out.print("The area of the hexagon is: " + hexagonArea(s)+"\n");
    }
    public static double hexagonArea(double s) {
        return (6*(s*s))/(4*Math.tan(Math.PI/6));
    }
}

Sample Output:

Input the length of a side of the hexagon: 6                                                                  
The area of the hexagon is: 93.53074360871938

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