首页  >  文章  >  Java  >  在Java中找到以相似弦为中心的角度

在Java中找到以相似弦为中心的角度

WBOY
WBOY转载
2023-09-16 18:53:02795浏览

在Java中找到以相似弦为中心的角度

圆是没有角的圆形二维图。每个圆都有一个原点,圆上的每个点到原点的距离都相等。原点与圆中一点之间的距离称为圆的半径。同样,如果我们从圆的一条边到另一条边画一条线,并且原点位于该线的中间,则该线称为圆的直径。基本上,直径是半径长度的两倍。

圆的弦是指从圆的一个端点到圆的另一个端点的连线。或者简单地说,弦是指端点位于圆上的线。弦将圆分成两部分。

根据问题陈述,当给定圆的半径和弦在中心所对的角度时,我们必须找到弦的长度。

求弦长的逻辑 -

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

那么,让我们来探索一下。

向您展示一些实例

实例1

假设中心弦所对的角度 = 60

因此,中心处另一个相同长度的弦所对的角度 = 60

实例2

假设中心弦所对的角度 = 45

因此,中心处另一个相同长度的弦所对的角度 = 45

实例3

假设中心弦所对的角度 = 52

因此,中心处另一个相同长度的弦所对的角度 = 52

算法

  • 第 1 步 - 通过静态输入或用户输入获取弦所对的中心角度。

  • 步骤 2 - 使用上述逻辑找到另一个相同长度弦所对的中心角度。

  • 第 3 步 - 打印结果。

多种方法

我们通过不同的方式提供了解决方案。

  • 通过使用静态输入值

  • 通过使用用户定义的方法

  • 通过使用用户输入值

让我们一一看看该程序及其输出。

方法 1:使用静态输入值

示例

在这种方法中,我们在程序中初始化弦所对的角度。然后通过算法我们可以找到另一个弦所对的角度。

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");
   }
}

输出

Angle subtended at the center by the chord: 52 degrees

方法 2:使用用户定义的方法

示例

在这种方法中,我们接受用户输入的弦所对的角度。然后通过将此值作为参数传递来调用用户定义的方法,并在方法内部使用算法我们可以找到另一个弦所对的角度。

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");
   }
}

输出

Angle subtended at the centre by the chord: 40 degrees

方法 3:使用用户输入值

示例

在这种方法中,我们在程序中接受用户输入的弦所对的角度。然后通过算法我们可以找到另一个弦所对的角度。

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");
   }
}

输出

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

在本文中,我们探讨了如何在 Java 中使用不同的方法给出另一个相同长度的弦所对的角度时找到一个弦所对的角度。

以上是在Java中找到以相似弦为中心的角度的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除