[英]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.