簡體   English   中英

如何讓我的計算器以度數而不是弧度計算

[英]How do I make my calculator this to calculate in degrees rather than radians

我已經堅持了很長時間。 如何讓我的計算器以度數而不是弧度計算。 我試過 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);
    
 }
}

使用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);
    
 }
}

為什么你需要那個? 編程語言將始終使用弧度進行計算。 您可以接受以度為單位的輸入,然后將其轉換為弧度,進行計算並將其轉換回輸出的度數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM