# Calculate the arc length of an angle in Java

In this tutorial, we will see how to calculate the arc length for a given angle in Java.

Mathematically, arc length is calculated as follows:

The length of an arc is equal to the circumference of the circle(2* π*r), times the fraction of the circle represented by the arc’s measure. Since a circle has a total angle of 360°. Therefore, on dividing an arc’s degree measure by it, we will be able to find the fraction of the circumference of the circle that the arc makes up. Hence, if we multiply the circumference by this fraction of the degree measure of an arc to the total angle, then we get the length of the arc.

Formula:

Arc length  = (Θ ÷ 360) * (2 * π * radius)

OR

A = (Θ ÷ 360) * (diameter * π)

where, Θ  is the degree measure of arc.

## Java Code:

```import java.io.*;
public class prog {
public static void main(String args[])throws IOException {
System.out.println("Angle : ");
double arc_length;

if (angle > 360) {
System.out.println("Invalid angle");
}
else {
arc_length = (2*Math.PI * radius) * (angle / 360.0);
System.out.println("Arc length : "+arc_length);
}

}
}```

We will prompt the user to enter the values of radius and degree measure of the arc whose length is to be calculated. For that, we will use the BufferedReader class to take the user input.

After creating an object of BufferedReader class, we will use the ob.readLine() method to read the value as a string and then parse it into a double type since radius and angle will be floating-point numbers.

• If the user enters the value of the angle more than 360, we will not proceed with the calculation.

Using these values, we can now calculate the arc length.
We have used the mathematical formula for our calculation.

Finally, we display the value.

Output:

```Radius : 4
Angle: 30
Arc Length : 2.0943```

So we are successfully able to calculate the arc length of an angle in Java programming language. I hope you have understood our program for this task.