我如何使我的计算器以度量而不是弧度计算

发布于 2025-02-13 03:04:12 字数 841 浏览 0 评论 0原文

我一直陷入困境很长一段时间。我如何使计算器以度而不是弧度计算。我尝试了Math.todegrees,但它不起作用。如果您决定提供帮助,谢谢。

导入Java.util.Scanner;

public class Main {

 public static void main(String[] args) {
     
  Scanner scanner = new Scanner(System.in);
  

  // END USER INPUT VALUE IN DEGREES
  System.out.println("Please input a value to recieve the Trigonemetric value in degrees ");

  double degrees = scanner.nextDouble();
  
  double sineOfAngle = Math.sin(degrees); 
  double cosOfAngle = Math.cos(degrees); 
  double tanOfAngle = Math.tan(degrees);

  System.out.println();
  System.out.println("The Sine of " + degrees + " degrees is : "
    + sineOfAngle);
  System.out.println("The Cosine of " + degrees + " degrees is : "
    + cosOfAngle);
  System.out.println("The Tangent of " + degrees + " degrees is : "
    + tanOfAngle);
    
 }
}

I have been stuck on this for a very long bit of time. How do I make my calculator calculate in degrees rather than radians. I tried Math.toDegrees but it did not work. Thank you if you decide to help.

import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
     
  Scanner scanner = new Scanner(System.in);
  

  // END USER INPUT VALUE IN DEGREES
  System.out.println("Please input a value to recieve the Trigonemetric value in degrees ");

  double degrees = scanner.nextDouble();
  
  double sineOfAngle = Math.sin(degrees); 
  double cosOfAngle = Math.cos(degrees); 
  double tanOfAngle = Math.tan(degrees);

  System.out.println();
  System.out.println("The Sine of " + degrees + " degrees is : "
    + sineOfAngle);
  System.out.println("The Cosine of " + degrees + " degrees is : "
    + cosOfAngle);
  System.out.println("The Tangent of " + degrees + " degrees is : "
    + tanOfAngle);
    
 }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩发小公举 2025-02-20 03:04:12

使用Math.toradians(),您想将学位转换为弧度,因为数学三角函数参数应在弧度中:

public class Main {

 public static void main(String[] args) {
     
  Scanner scanner = new Scanner(System.in);
  

  // END USER INPUT VALUE IN DEGREES
  System.out.println("Please input a value to recieve the Trigonemetric value in degrees ");

  double degrees = scanner.nextDouble();
  
  double sineOfAngle = Math.sin(Math.toRadians(degrees)); 
  double cosOfAngle = Math.cos(Math.toRadians(degrees)); 
  double tanOfAngle = Math.tan(Math.toRadians(degrees));

  System.out.println();
  System.out.println("The Sine of " + degrees + " degrees is : "
    + sineOfAngle);
  System.out.println("The Cosine of " + degrees + " degrees is : "
    + cosOfAngle);
  System.out.println("The Tangent of " + degrees + " degrees is : "
    + tanOfAngle);
    
 }
}

use Math.toRadians(), You want to convert the degrees to radians because the Math trigonometric functions parameters should be in radians:

public class Main {

 public static void main(String[] args) {
     
  Scanner scanner = new Scanner(System.in);
  

  // END USER INPUT VALUE IN DEGREES
  System.out.println("Please input a value to recieve the Trigonemetric value in degrees ");

  double degrees = scanner.nextDouble();
  
  double sineOfAngle = Math.sin(Math.toRadians(degrees)); 
  double cosOfAngle = Math.cos(Math.toRadians(degrees)); 
  double tanOfAngle = Math.tan(Math.toRadians(degrees));

  System.out.println();
  System.out.println("The Sine of " + degrees + " degrees is : "
    + sineOfAngle);
  System.out.println("The Cosine of " + degrees + " degrees is : "
    + cosOfAngle);
  System.out.println("The Tangent of " + degrees + " degrees is : "
    + tanOfAngle);
    
 }
}
森罗 2025-02-20 03:04:12

你为什么需要那个?编程语言将始终使用弧度进行计算。您可以以度量接受输入,然后将其转换为弧度,进行计算并将其转换回输出程度。

Why you need that? Programming language will always use radians for calculation. You can accept input in degrees, then convert it to radians, make calculation and convert it back to degrees on output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文