In the previous article, we have discussed about Java Program to Find Arc Length from Given Angle
In this article we are going to see how to find radius of circle when width and height of arc is given using Java programming language.
Java Program to Find Radius of Circle When Width and Height of Arc is Given
Before Jumping into the program directly let’s see how to find radius of circle when width and height of arc length is given.
Let’s assume
Radius of the circle be r
Height of the arc h
.
Width of the arc w
.
Now,
We know, perpendicular bisector drawn from the center to the chord bisects the chord AB in two halves, each having length w/2
Simultaneously, the diameter is also divided by the chord in two parts, the part inside arc h
and the remaining 2r-h
Now,
Using intersecting chords theorem,
h*(2r-h) = (w/2)2
2rh – h2 = w2/4
r = w2/8h + h/2
Example:
h = 4
w = 8
r = w2/8h + h/2 = 4
Let’s see different ways how to find radius of circle when width and height of arc is given.
Method-1: Java program to Find Radius of Circle When Width and Height of Arc is Given By Using Static Input Value
Approach:
- Declare an double variable say ‘
h
’ and assign the value to it, which holds the height of the chord. - Declare an double variable say ‘
w
’ and assign the value to it, which holds the width of the chord. - Find the radius using the formula w2/8h + h/2
- Print the result.
Program:
import java.io.*; class Main { public static void main(String [] args) { double h = 4; double w = 8; double r = ((w*w)/(8*h)+(h/2)); // formula to find radius System.out.println("The radius of the circle is "+ r); } }
Output: The radius of the circle is 4.0
Method-2: Java program to Find Radius of Circle When Width and Height of Arc is Given By Using User Input Value
Approach:
- Declare an double variable say ‘
h
’ which holds the height of the chord. - Declare an double variable say ‘
w
’ which it holds the width of the chord. - Then we will take the value of “h”, “w” as user input using scanner class.
- Find the radius using the formula w2/8h + h/2
- 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 height of the chord"); // to take user input value double h = s.nextDouble(); System.out.println("Enter the width of the chord"); double w = s.nextDouble(); // formula to find radius double r = ((w*w)/(8*h)) + (h/2); System.out.println("The radius of the circle is " + r); } }
Output: Enter the height of the chord 1 Enter the width of the chord 4 The radius of the circle is 2.5
Beginners and experienced programmers can rely on these Best Java Programs Examples and code various basic and complex logics in the Java programming language with ease.
Related Java Programs:
- Java Program to Find Equation of Circle From Radius and Center
- Java Program to Find Minimum Revolutions to Move Center of a circle to a Target
- Java Program to Find Area of the Larger Circle when Radius of the Smaller circle and Difference in the Area is Given
- Java Program to Find Area of an Circle Inscribed in a Square