# JAVA Program to Calculate Length of Chord of the Circle

A circle is a round shape two-dimensional diagram which has no corners. Every circle has an origin point and every point on the circle maintains equal distance from the origin. The distance between the origin and a point in a circle is known as Radius of the circle. And similarly, if we draw a line from one edge to another edge of the circle and the origin is held in the middle of it, that line is known as diameter of the circle. Basically, the diameter is double of the length of the radius.

Chord of the circle refers to a line touching from one endpoint of circle to another end point of circle. Or simply we can say a chord refers to the line whose endpoints lie on the circle. A chord divides the circle into two parts.

As per the problem statement we have to find the length of the chord when the radius of circle and angle subtended at centre by the chord is given.

Formula to find length of chord −

Length = 2 * r * sin(a/2)


Where, ‘r’ refers to the radius of the circle and ‘a’ refers to the angle subtended at centre by the chord.

So, let’s explore.

## To show you some instances −

### Instance-1

Let say radius (r) of circle is 3.
And angle (a) subtended at centre by the chord is 60
Then by using the formula, length of the chord is 5.19.


### Instance-2

Let say radius (r) of circle is 4.
And angle (a) subtended at centre by the chord is 50
Then by using the formula, length of the chord is 6.12.


### Instance-3

Let say radius (r) of circle is 4.
And angle (a) subtended at centre by the chord is 40.
Then by using the formula, length of the chord is 5.1.


### Algorithm

Step-1 − Get the radius of circle and angle at the centre subtended by the chord either by static input or by user input.

Step-2 − Find the length of the chord by using the formula.

Step-3 − Print the result.

### Multiple Approaches

We have provided the solution in different approaches.

• By Using Static Input Values.

• By Using User Input Values.

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

## Approach-1: By Using Static Input Value

In this approach, we initialize the radius and angle value in the program. Then by using the algorithm we can find the length of the chord.

## Example

public class Main {
//main method
public static void main(String[] args) {
double r = 4;
//angle subtended by chord at center
double a = 40;
//find length of chord by using formula
double length = 2 * r * Math.sin(a * (3.14 / 180));
System.out.println("Length of Chord: "+length);
}
}


## Output

Length of Chord: 5.140131589369607


## Approach-2: By Using User Defined Method with Static Input Value.

In this approach, we take user input of radius and angle value in the program. Then call a user defined method by passing these values as parameters and inside the method by using the algorithm we can find the length of the chord.

## Example

public class Main {
//main method
public static void main(String[] args) {
double r = 4;
//angle subtended by chord at center
double a = 40;
length_of_chord(r, a);
}
//user defined method to find the length of the chord
static void length_of_chord(double r, double a) {
double length = 2 * r * Math.sin(a * (3.14 / 180));
System.out.println("Length of Chord: "+length);
}
}


## Output

Length of Chord: 5.140131589369607


In this article, we explored how to find the length of the chord when the radius ofcircle and angle subtended by chord to centre is given by using different approaches in Java.