
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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) { //radius of circle 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) { //radius of circle 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.
- Related Articles
- JAVA Program to Find Length of Longest Chord of a Circle
- JAVA Program to Calculate Shortest Distance from Center of the Circle to Chord
- In a circle of diameter \( 40 \mathrm{~cm} \) the length of a chord is \( 20 \mathrm{~cm} \). Find the length of minor arc corresponding to the chord.
- JAVA Program to Calculate Radius of Circle with Given Width and Height of Arc
- Prove that a diameter of a circle which bisects a chord of the circle also bisects the angle subtended by the chord at the centre of the circle.
- Fill in the blanks:The longest chord of a circle is a ……… of the circle.
- Two concentric circles are of radii 5 cm and 3 cm. Find the length of the chord of the larger circle which touches the smaller circle.
- If two equal chords of a circle intersect within the circle, prove that the segments of one chord are equal to corresponding segments of the other chord.
- In a circle of radius \( 6 \mathrm{~cm} \), a chord of length \( 10 \mathrm{~cm} \) makes an angle of \( 110^{\circ} \) at the centre of the circle. Find the circumference of the circle.
- In a circle of radius \( 6 \mathrm{~cm} \), a chord of length \( 10 \mathrm{~cm} \) makes an angle of \( 110^{\circ} \) at the centre of the circle. Find the area of the circle.
- Swift Program to Calculate Area of Circle Inscribed in Square
- In a circle of radius \( 6 \mathrm{~cm} \), a chord of length \( 10 \mathrm{~cm} \) makes an angle of \( 110^{\circ} \) at the centre of the circle. Find the length of the arc \( A B \).
- Program to calculate the area of an Circle inscribed in a Square
- Java program to find the area of a circle
- Java program to find the circumference of a circle
