-3

seems like I just have trouble getting the equation written down but im dealing with this question :

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

enter image description here

A=area , a=side length

Here is what I have so far

import java.util.Scanner;
public class Areahexagon


{
  public static void main(String [] args)
  {
    double s;
    Scanner sid = new Scanner(System.in);

    System.out.println("Enter side's number for hexagons area");

  s = sid.nextDouble();

  System.out.println("The area is ");

    double area = ((Math.sqrt(3/3) / 2) + Math.Pow 2);
  System.out.println(distance);
  }
}
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Moiz Khan
  • 29
  • 2

1 Answers1

6

Try this formula

double area = (3*(Math.sqrt(3))*s*s)/2;

The formula for area of hexagon is 3 multiplied by sqrt of 3 multiplied by the side square and divided by 2. In this case, you are not using Math class correctly for getting square root of 3. Also, you are not getting square of the side in his code and instead using Math.Pow 2 - which is incorrect.

Balwinder Singh
  • 2,272
  • 5
  • 23
  • 34