Java 三角学需要图书馆吗

Java 三角学需要图书馆吗,java,Java,我正在尝试运行此代码,但没有得到任何结果。代码或编译器是否有问题?有人能告诉我java的新知识吗 public class MathTrigonometricExample { public static void main(String[] args) { double radians = 45.0; double sine = Math.sin(radians); System.out.println("The Sin of " +

我正在尝试运行此代码,但没有得到任何结果。代码或编译器是否有问题?有人能告诉我java的新知识吗

public class MathTrigonometricExample {
    public static void main(String[] args) {
        double radians = 45.0;

        double sine = Math.sin(radians);
        System.out.println("The Sin of " + radians + " = " + sine);

        double cosine = Math.cos(radians);
        System.out.println("The Cos of " + radians + " = " + cosine);

        double tan = Math.tan(radians);
        System.out.println("The Tan of " + radians + " = " + tan);

        double asine = Math.asin(sine);
        System.out.println("Arcsine of " + sine + " = " + asine);

        double acosine = Math.acos(cosine);
        System.out.println("Arccosine of " + cosine + " = " + acosine);

        double atan = Math.atan(tan);
        System.out.println("Arctangent of " + tan + " = " + atan);

        double sinh = Math.sinh(radians);
        System.out.println("hyperbolic sine of " + radians + " = " + sinh);

        double cosh = Math.cosh(radians);
        System.out.println("hyperbolic cos of " + radians + " = " + cosh);

        double tanh = Math.tanh(radians);
        System.out.println("hyperbolic tan of " + radians + " = " + tanh);
    }
}

tri函数采用弧度,而不是度。45.0看起来像度,而
Math.PI/4
看起来像弧度

答案是,只要使用弧度,就可以使用内置库。如果需要将度转换为弧度,可以使用以下方法

double degress = 45.0;
double radians = degress * Math.PI / 180;
线程“main java.lang.NoclssDefoUnderError:mathtrygonometric示例中出现异常(错误名称:cin/java/connect/math/MathTrigonometriceExample)

这表明您试图运行错误的类名。当提出问题时,值得包含所有相关的错误消息,因为我们无法读懂您的心思。;)


我建议您使用IDE,因为这将使编辑、编译和运行程序更容易。

它可以正确编译和运行。您确定您已将源文件保存为“MathTrigonogrationExample.java”吗


如果是,您是否确定要运行的路径正确?(指向.class文件所在的位置)

您能否提供有关线程“main java.lang.noclssdeffounder”中的.exception错误的更多详细信息错误:MathTryGonometrice示例(错误名称:cin/java/connect/math/MathTrigonometrice示例)那么,您可能从错误的路径运行它。您是否尝试过在java中运行helloworld?尝试注释掉所有代码,然后再次运行。你很可能在启动应用程序时遇到问题。你注意到拼写上的差异了吗(mathtrygonometric与MathTrigonal)?也就是说,这会导致OP面临的问题吗?只是想知道这是一个答案还是更多的建议/评论。虽然这一条可能有用(仍然有可能OP故意将角度设置为45弧度),它肯定不能回答这个问题。它看起来像是OP在程序运行并产生一些答案后要问的问题的答案。我想他知道弧度变量名。更不用说45是一个完全有效的弧度值。Sin(45)=.851。外表可能会欺骗人。@C.Lang这是合法的,但你可以期待
asin(sin)
给你45分。