In the previous article, we have discussed about Java Program to Check if Two Convex Regular Polygon Have Same Center or Not

In this article we are going to see how to find interior and exterior angle of regular polygon by using Java programming language.

## Java Program to Find Interior and Exterior Angle of Regular Polygon when Number of Sides of Polygon is Given

Before Jumping into the program directly let’s see how to find interior and exterior angle of regular polygon.

**Explanation:**

Suppose there is a polygon N sides

Where N>=3

Now, we need to find the interior and exterior angle of the polygon

Interior angle = (N-2)*180/N

Exterior angle = 360/N

**Example: **

N = 5 Interior angle = (N-2)*180/N = 108 Exterior angle = 360/N = 72

Let’s see different ways to find interior and exterior angle of regular polygon.

### Method-1: Java Program to Find Interior and Exterior Angle of Regular Polygon By Using Static Value

**Approach:**

- Declare an int variable say ‘N’ and assign the value to it, which holds the Of sides of N-sided Polygon
- Find the interior and exterior angle using the formula
`Interior angle = (N-2)*180/N`

and`Exterior angle = 360/N`

- Print the result.

**Program:**

import java.util.*; public class Main { public static void main(String[] args) { //number of sides of polygon is declared int N = 8; // formula to find the interior and exterior angle of the polygon int interiorAngle = (N-2)*180/N; int exteriorAngle = 360/N; System.out.println("The interior angle of the polygon is " + interiorAngle + " deg"); System.out.println("The exterior angle of the polygon is " + exteriorAngle + " deg"); } }

Output: The interior angle of the polygon is 135 deg The exterior angle of the polygon is 45 deg

### Method-2: Java Program to Find Interior and Exterior Angle of Regular Polygon By Using User Input Value

**Approach:**

- Declare an int variable say ‘N’ and take the value as user input, it refers to number of sides of N-sided Polygon
- Find the interior and exterior angle using the formula
`Interior angle = (N-2)*180/N`

and`Exterior angle = 360/N`

- Print the result.

**Program:**

import java.util.*; public class Main { public static void main(String[] args) { //Scanner class object created Scanner s = new Scanner(System.in); //taking input of number of sides of polygon from user System.out.println("Enter the no. Of sides of a N-sided polygon"); int N = s.nextInt(); // formula to find the interior and exterior angle of the polygon int interiorAngle = (N-2)*180/N; int exteriorAngle = 360/N; System.out.println("The interior angle of the polygon is " + interiorAngle + " deg"); System.out.println("The exterior angle of the polygon is " + exteriorAngle + " deg"); } }

Output: Enter the no. Of sides of a N-sided polygon 6 The interior angle of the polygon is 120 deg The exterior angle of the polygon is 60 deg

Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples.

**Related Java Programs:**

- Java Program to Find Angle of Intersection of Two Circles Having Their Centers D Distance Apart
- Java Program to Find Ratio of the distance between the Centers of the Circles and the Point of Intersection of Two Direct Common Tangents to the Circles
- Java Program to Find Distance between Centers of Two Intersecting Circles if the Radius and Common Chord Length is Given
- Java Program to Find Length of the Chord of the Circle if Length of Another Chord Which is Equally Inclined through the Diameter is Given