Java Program to Find Arc Length from Given Angle

In the previous article, we have discussed about Java Program to Find Shortest Distance from Center of a Circle to a Chord

In this article we are going to see how to find arc length from given angle using Java programming language.

Java Program to Find Arc Length from Given Angle

Before Jumping into the program directly let’s see how to Find Arc Length from Given Angle.

Angle: In geometry, when two lines meets at a common end point then the figure formed by them is called as an angle.

Arc Length: In a circle, the length of an arc is a portion of the circumference.

To find the arc length from a given angle is :

Arc length = (circumference of the circle) * (Angle/360)

L = 2 * pi * R * A/360

Where,

  • L – arc length
  • Pi = 3.142
  • R – radius of the circle
  • A – angle in degree

Example:

r = 3
A = 120
L = 2 * pi * R * A/360 
= 2*3.142*3*(120/360) 
= 18*3.142 
= 6.284

Let’s see different ways find arc length from given angle.

Method-1: Java Program to Find Arc Length from Given Angle By Using Static Input Value

Approach:

  • Declare a double variable say ‘r’ and assign the value to it, which holds the radius value of the circle.
  • Declare a double variable say ‘a’ and assign the value to it, which holds the angle value in degree.
  • Find the Arc length using the formula 2 * pi * R * A/360
  • Print the result.

Program:

import java.io.*;
class Main
{
    public static void main(String [] args)
    {
        double r = 3;
        double a = 120;    
        // formula to find arc length
        double l =  2 * 3.142 * r * a/360;
        System.out.println("The arc length of the given angle is =" + l);
    }
}
Output:

The arc length of the given angle is =6.284000000000001

Method-2: Java Program to Find Arc Length from Given Angle By Using User Input Value

Approach:

  • Declare a double variable say ‘r’ which holds the radius value of the circle.
  • Declare a double variable say ‘a’ which holds the angle value in degree.
  • Then we will take the value of “r”, “a” as user input using scanner class.
  • Find the Arc length using the formula 2 * pi * R * A/360
  • Print the result.

Program:

import java.io.*;
import java.util.Scanner;
class Main
{
    public static void main(String [] args)
    {
         // scanner class obj ref
        Scanner s = new Scanner(System.in);                              
        System.out.println("Enter the length of radius of the circle");
         // to take user input value
        double r = s.nextDouble();                                         
        System.out.println("Enter the value of angle in degree");
        double a =  s.nextDouble();
       // formula to find arc length
        double l =  2 * 3.142 * r * a/360;
        System.out.println("The arc length of the given angle is " + l);         
    }
}
Output:

Enter the length of radius of the circle
5
Enter the value of angle in degree
48.5
The arc length of the given angle is 4.232972222222222

Access the Simple Java program for Interview examples with output from our page and impress your interviewer panel with your coding skills.

Related Java Programs: