A circle is a circular two-dimensional figure without corners. Every circle has a starting point, and every point on the circle is equidistant from the starting point. The distance between the starting point and a point on the circle is called the radius of the circle. Similarly, if we draw a line from one side of a circle to the other with the starting point in the middle, that line is called the diameter of the circle. Basically, the diameter is twice the length of the radius.
An arc refers to a part of a circle or a circumference. Simply put, it is an open curve on the circumference of a circle.
According to the problem statement, we need to find the radius of the circle when the width and height of the arc are given.
The formula for calculating the radius of a circle using a given arc width and arc height is −
$$mathrm{r=w^{2}/8h h/2}$$
Where, 'r' is the radius of a circle.
‘h’ is the height of the arc, ‘w’ is the width of the arc.
So, let us go ahead and see how to find the radius of a circle with given arc width and arc height using Java programming language.
Let say height (h) of arc = 2. And width of (w) of arc = 4 Radius of circle by using given width and height of arc = 2
Let say height (h) of arc = 3. And width of (w) of arc = 5 Radius of circle by using given width and height of arc = 2.54
Let say height (h) of arc = 1. And width of (w) of arc = 4. Radius of circle by using given width and height of arc = 2.5.
To get any power of a number in Java, we can use the built-in java.lang.Math.pow() method.
The following is the syntax for using the method to obtain the power of 2 -
double power = Math.pow (inputValue,2)
Step-1 − Get the width and height of the arc through static input or user input.
Step-2 − Find the radius of the circle by using the formula.
Step 3 - Print the results.
We provide solutions in different ways.
By using static input values.
By using user-defined methods.
Let's look at the program and its output one by one.
In this method, we declare two double variables to hold the width and height values of the arc and initialize these values in the program. Then by using an algorithm we can find the radius of the circle.
The Chinese translation ofpublic class Main { //main method public static void main(String[] args) { //width (w) and height (h) of arc double w = 5, h = 3; //find radius using the formula double r = ((w * w) / (8 * h) + h / 2); System.out.println( "Radius of the circle: "+r); } }
Radius of the circle: 2.541666666666667
In this method, we declare two double variables to hold the width and height values of the arc and take these values as user input. Then call a user-defined method by passing these values as parameters. Then inside the method, by using an algorithm, we can find the radius of the circle.
The Chinese translation ofpublic class Main { //main method public static void main(String[] args) { //width (w) and height (h) of arc double w = 5, h = 2; //call the user defined method to get the radius findRadius(w, h); } //find radius of circle static void findRadius(double w, double h) { //find radius using the formula double r = ((w * w) / (8 * h) + h / 2); System.out.println( "Radius of the circle: "+r); } }
Radius of the circle: 2.5625
In this article, we explored how to find the radius of a circle in Java, when the width and height of the arc of the circle are known, using different methods.
The above is the detailed content of JAVA program to calculate radius of circle using given width and height of arc. For more information, please follow other related articles on the PHP Chinese website!