Hexagon area

 Hexagon area


Problem Description


Write a program that prompts the user to enter the side of a hexagon and displays its area.


Use Double Data Type and


String.format(" %.2f", outputValue);

Logic Test Case 1


Input (stdin)

5.12


Expected Output


68.11

Logic Test Case 2


Input (stdin)

3.4


Expected Output


30.03




Code Area



import java.io.*;

import java.util.Scanner;

public class TestClass {

public static void main(String[] args) {

       Scanner input=new Scanner(System.in);

       double side=input.nextDouble();

       double area=(6*Math.pow(side,2))/(4*Math.tan(Math.PI/6));

      String str1=String.format("%.2f",area);

       System.out.println(str1);

}

}

Post a comment

0 Comments