How to Calculate Area of Enneagon in Java?


An enneagon refers to a polygon with 9 sides with 9 internal angles. Where all the sides of the polygon are equal it is called a regular enneagon which has an internal angle of 140 degrees, and the sum of all internal angles are 1260 degrees. An enneagon is also referred to as Nonagon.

Area of enneagon can be calculated by using

When Length of Side (s) is given

Area = 6.1818 * (s * s)

When circumradius (r) is given

Area = 2.8925 * (r * r)

When apothem (a) is given

Area = 3.2757 * (a * a)

In this article, we will see how to calculate the area of the enneagon by using Java programming language.

To show you some instances

Instance-1

When Length of Side (s) = 4.5

By using the area formula of enneagon when Length of Sides are given,

Area = 125.18

Instance-2

When circumradius (r) = 5

By using the area formula of enneagon when circumradius is given,

Area = 72.31

Instance-3

When apothem (a) = 6

By using the area formula of enneagon when apothem is given,

Area = 117.92

Syntax

To get the power of any number raised to the power of another number in Java we haveinbuilt java.lang.Math.pow() method.

Following is the syntax to get power of 2 by using the method 

double power = Math.pow (inputValue,2)

Algorithm

  • Step 1 − Get the side length of circumradius or apothem of the enneagon either by initialization or by user input.

  • Step 2 − Then calculate the area by using the respective area formula of the enneagon.

  • Step 3 − Print the area value of the enneagon.

Multiple Approaches

We have provided the solution in different approaches.

  • By Using Length of Side (s)

  • By Using circumradius (r)

  • By Using apothem (a)

Let’s see the program along with its output one by one.

Approach-1: By Using Length of Sides (s)

In this approach, declare and initialize the side length value of the enneagon. Then by using the algorithm find the area.

Example

import java.util.*; public class Main { //main method public static void main(String[] args) { //side length of enneagon double s = 5.5; //find area by using formula double area = 6.1818 * (s * s); //print the result System.out.println("Area of enneagon is: " + area); } }

Output

Area of enneagon is: 186.99945

Approach-2: By Using Circumradius (r)

In this approach, declare and initialize the circumradius of the enneagon. Then by using the algorithm find the area.

Example

import java.util.*; public class Main { //main method public static void main(String[] args) { //circumradius of enneagon double r = 4.5; //find area by using formula double area = 2.8925 * (r * r); //print the result System.out.println("Area of enneagon is: " + area); } }

Output

Area of enneagon is: 58.573125000000005

Approach-3: By Using Apothem (a)

In this approach, declare and initialize the apothem of the enneagon. Then by using the algorithm find the area.

Example

import java.util.*; public class Main { //main method public static void main(String[] args) { //apothem of enneagon double a = 6; //find area by using formula double area = 3.2757 * (a * a); //print the result System.out.println("Area of enneagon is: " + area); } }

Output

Area of enneagon is: 117.9252

In this article, we explored how to calculate the area of the enneagon in Java by using different approaches.

Updated on: 17-Nov-2022

95 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements