Monday 23 March 2020

DISPLAYING AREA OF A HEXAGON USING JAVA LANGUAGE

Q-20- Write a java 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

                                         𝐴𝑟𝑒𝑎 =3√3*X*X /2
where s is the length of a side.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double side;
System.out.println("Enter The Side:");
side=sc.nextDouble();
double p=Math.pow(3, 0.5);
double area=3*p*side*side/2;
System.out.println("The Area Of The Hexagon Is: "+area);
}


}

OUTPUT :
Enter The Side:
5.5

The Area Of The Hexagon Is: 78.59180539343781

No comments:

Post a Comment