-2

我正在尝试运行此代码,但没有得到任何结果..代码或我的编译器有问题吗?有人可以指出我在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);
    }
}
4

2 回答 2

2

它编译并正确运行。您确定您已将源文件保存为“MathTrigonometricExample.java”吗?

如果是,你确定你的目标是正确的运行路径吗?(到 .class 文件所在的位置)

于 2013-03-26T08:16:45.297 回答
1

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

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

double degress = 45.0;
double radians = degress * Math.PI / 180;

线程中的异常“main java.lang.noclssdeffounderror:mathtrygonometric 示例(错误名称:cin/java/connect/math/mathtrigonometricexample)

这表明您正在尝试运行错误的类名。在提出问题时,值得包括所有相关的错误消息,因为我们无法读懂您的想法。;)

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

于 2013-03-26T08:14:46.830 回答