Home > Java > javaTutorial > Find angles centered on similar chords in Java

Find angles centered on similar chords in Java

WBOY
Release: 2023-09-16 18:53:02
forward
851 people have browsed it

Find angles centered on similar chords in Java

A circle is a circular two-dimensional figure without corners. Every circle has an origin, and every point on the circle is equidistant from the origin. The distance between the origin and a point in the circle is called the radius of the circle. Likewise, if we draw a line from one side of a circle to the other and the origin is in the middle of the line, then the line is called the diameter of the circle. Basically, the diameter is twice the length of the radius.

The chord of a circle refers to the line connecting one endpoint of the circle to the other endpoint of the circle. Or simply put, a chord is a line whose endpoints lie on a circle. The chord divides the circle into two parts.

According to the problem statement, we must find the length of the chord when given the radius of the circle and the angle subtended by the chord at the center.

The logic of finding the string length -

Angle subtended by the chord at centre = Angle subtended by another chord of same length at centre
Copy after login

So, let’s explore.

Show you some examples

Example 1

Assume the angle subtended by the center chord = 60

Therefore, the angle subtended by another string of the same length at the center = 60

Example 2

Assume the angle subtended by the center chord = 45

Therefore, the angle subtended by another string of the same length at the center = 45

Example 3

Assume the angle subtended by the center chord = 52

Therefore, the angle subtended by another string of the same length at the center = 52

algorithm

  • Step 1 - Get the center angle subtended by the string via static input or user input.

  • Step 2 - Use the logic above to find the central angle subtended by another string of the same length.

  • Step 3 - Print the results.

Multiple methods

We provide solutions in different ways.

  • By using static input values

  • By using user-defined methods

  • By using user input value

Let’s look at the program and its output one by one.

Method 1: Using static input values

Example

In this method, we initialize the angle subtended by the string in the program. Then through algorithm we can find the angle subtended by the other string.

import java.io.*;
public class Main{

   //main code
   public static void main (String[] args){
   
      //angle subtended by chord
      int angle = 52;
      System.out.println("Angle subtended at the center by the chord: "+angle+" degrees");
   }
}
Copy after login

Output

Angle subtended at the center by the chord: 52 degrees
Copy after login

Method 2: Using user-defined methods

Example

In this method, we accept the user input of the angle subtended by the string. Then calling the user defined method by passing this value as parameter and using algorithm inside the method we can find the angle subtended by the other string.

import java.io.*;
public class Main{

   //main code
   public static void main (String[] args){
   
      //angle subtended by chord
      int angle = 40;
      findAngle(angle);
   }
    
   //user defined method to find the angle subtended by another chord
   static void findAngle(int angle){
      System.out.println("Angle subtended at the centre by the chord: "+angle+" degrees");
   }
}
Copy after login

Output

Angle subtended at the centre by the chord: 40 degrees
Copy after login

Method 3: Using user input values

Example

In this method, we accept the angle subtended by the string as input by the user in the program. Then through algorithm we can find the angle subtended by the other string.

import java.io.*;
import java.util.*; 
public class Main{

   //main code
   public static void main (String[] args){
   
      //Create object of Scanner class
      Scanner sc = new Scanner(System.in);
      
      //angle subtended by chord
      System.out.println("Enter the angle subtended at center by the chord:");
      int angle = sc.nextInt();
      System.out.println("Angle subtended at the center by the chord: "+angle+" degrees");
   }
}
Copy after login

Output

Enter the angle subtended at center by the chord:
55
Angle subtended at the center by the chord: 55 degrees
Copy after login

In this article, we looked at how to find the angle subtended by one string given the angle subtended by another string of the same length using different methods in Java.

The above is the detailed content of Find angles centered on similar chords in Java. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template