- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Get Interior & Exterior Angle of Regular Polygon When Numbers of Sides of Polygon is Given in Java

A polygon is a 2-dimensional closed shape that has at least 3 sides. Depending on the number of sides, relationships of the sides and angles, and other characteristics, polygons can be classified under different names like triangles, squares, and quadrilaterals.

An interior angle of a polygon is an angle formed inside the two adjacent sides of a polygon.

Exterior angle is defined as the angle formed between a side of triangle and an adjacent side extending outward.

In this article, we will find interior and exterior angle of regular polygon when numbers of sides of polygon is given i.e “m”

Formula to find interior angle of a polygon:

Interior angle = ((n – 2) * 180)/n

Formula to find exterior angle of a polygon:

Exterior angle = 360/n

Let's start!

**For instance**

Suppose the value of m = 7.

Then putting the value of “m” in the formula of interior and exterior angle, the result will be:

The interior angle of polygon is: 128

The exterior angle of polygon is: 51

## Algorithm

**Step-1**: Declare and initialize the variables.

**Step-2**: Find the interior angle using the formula.

**Step-3**: Find the exterior angle using the formula

**Step-4**: Print the result.

## Multiple Approaches

We have provided the solution in different approaches.

By Using Static Inputs

By Using User Defined Method

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

## Approach-1: By Using Static Input

In this approach, value of “m” will be assigned. Then as per the algorithm we will find the interior and exterior angle of regular polygon when numbers of sides of polygon.

### Example

public class Main { //main method public static void main (String[] args) { //declaring variables int m = 15; int angle_interior, angle_exterior; //finding the interior angle angle_interior = (m - 2) * 180 / m; //finding the exterior angle angle_exterior = 360 / m; //print the Interior angle System.out.println("The interior angle of polygon is: " + angle_interior); //print the exterior angle System.out.println("The exterior angle of polygon is: " + angle_exterior); } }

### Output

The interior angle of polygon is: 156 The exterior angle of polygon is: 24

## Approach-2: By Using User Defined Method

In this approach, value of ”m” will be assigned. Then call a user defined method by passing the given values and as per the algorithm we will find the interior and exterior angle of regular polygon when numbers of sides of polygon

### Example

public class Main { //main method public static void main (String[] args) { //declaring variables int m = 7; //calling user defined method func(m); } //user defined method static void func(int m) { int angle_interior, angle_exterior; //finding the interior angle angle_interior = (m - 2) * 180 / m; //finding the exterior angle angle_exterior = 360 / m; //print the Interior angle System.out.println("The interior angle of polygon is: " + angle_interior); //print the exterior angle System.out.println("The exterior angle of polygon is: " + angle_exterior); } }

### Output

The interior angle of polygon is: 128 The exterior angle of polygon is: 51

In this article, we explored how to find the interior and exterior angle of a regular polygon when numbers of sides of a polygon are given by using Java programming language.