Java Program to Find Area of Enneagon

In the previous article, we have seen Java Program to Find Maximum Area of Quadrilateral

In this article we are going to see how to find the area of enneagon using Java programming language.

Java Program to Find Area of Enneagon

Before Jumping into the program directly let’s see how we can find the area of enneagon.

Explanation:

Enneagon is a polygon with 9 sides. As 9 sides so 9 internal angles are also there.
As Enneagon has 9 sides, so it is also called as Nonagon.
Formula to find area of enneagon (approx.) = 6.1818 * a * a

Where

  • a represents the side length of enneagon.

Example:

Let one of the sides of enneagon be “a” = 1

So, vol. of enneagon = 6.1818 * a * a = 6.1818 * 1 * 1 = 6.1818

Let’s see different ways to find the area of enneagon.

Method-1: Java Program to Find Area of Enneagon By Using Static Value

Approach:

  • Declare an integer variable say “s”, assign the value to it, which holds the value for one of the side length of enneagon.
  • Find the area of enneagon using the formula 6.1818 * a * a
  • Print the result.

Program:

class Main
{
    public static void main(String [] args)
    {
        //side length of enneagon declared
        int a = 1;
        //finding area using formula 
        double ar = 6.1818 * a * a;
        System.out.println("The area of enneagon is: " + ar);
    }
}

Output:

The area of enneagon is: 6.1818

Method-2: Java Program to Find Area of Enneagon By Using Static Value

Approach:

  • Declare an integer variable say “s”, take the value of s as user input, which holds the value for one of the side length of enneagon.
  • Find the area of enneagon using the formula 6.1818 * a * a
  • Print the result.

Program:

import java.util.*;

class Main
{
    public static void main(String [] args)
    {
        //Scanner class object created
        Scanner s = new Scanner(System.in);
        //Taking side length value as input from user
        System.out.println("Enter the value of one side of the enneagon: ");
        int a = s.nextInt();

        //finding area using formula 
        double ar = 6.1818 * a * a;
        System.out.println("The area of enneagon is: " + ar);
    }
}

Output:

Enter the value of one side of the enneagon: 
2
The area of enneagon is: 24.7272

Method-3: Java Program to Find Area of Enneagon By Using User Defined Method

Approach:

  • Declare an integer variable say “s”, take the value of s as user input, which holds the value for one of the side length of enneagon.
  • Then call a user defined method say findArea() and pass side length i.e ‘s‘ as parameter.
  • Inside the method find the area of enneagon using the formula 6.1818 * a * a
  • Print the result.

Program:

import java.util.*;

class Main
{
    public static void main(String [] args)
    {
        //Scanner class object created
        Scanner s = new Scanner(System.in);
        //Taking side length value as input from user
        System.out.println("Enter the value of one side of the enneagon: ");
        int a = s.nextInt();
        //calling the user defined method findArea()
        findArea(a);
    }

    //findArea() method tofind area of nonagon
    public static void findArea(int a)
    {
        //finding area using formula 
        double ar = 6.1818 * a * a;
        System.out.println("The area of enneagon is: " + ar);
    }
}

Output:

Enter the value of one side of the enneagon: 
3
The area of enneagon is: 55.6362

Guys who are serious about learning the concepts of the java programming language should practice this list of programs in java and get a good grip on it for better results in exams or interviews.

Related Java Articles: