java math.cos_Java Math类静态double cos(double d)示例

java math.cos

数学类静态双cos(double d) (Math Class static double cos(double d))

  • This method is available in java.lang package.

    此方法在java.lang包中可用。

  • This method is used to return the trigonometric cosine of an angle of the given parameter in the method. 

    此方法用于返回该方法中给定参数的角度的三角余弦。

  • In this method, cos stands for cosine of an angle.

    在此方法中,cos代表角度的余弦。

  • This is a static method so this method is accessible with the class name too. 

    这是一个静态方法,因此也可以使用类名访问此方法。

  • The return type of this method is double that means it returns the cosine value of the given angle and the value is of double type. 

    此方法的返回类型是double,这意味着它将返回给定角度的余弦值,并且该值是double类型。

  • In this method, we pass only one parameter as an argument in the method of Math class and the given parameter is those parameters for which we have to find the cosine of an angle. 

    在此方法中,我们仅将一个参数作为参数传递给Math类的方法,并且给定参数是那些我们必须找到角度的余弦值的参数。

  • In this method, we pass only radians type argument (i.e. First we convert given argument in radians by using toRadians() method of Math class then after we will pass the same variable in cos() method). 

    在此方法中,我们仅传递弧度类型的参数(即,首先,我们使用Math类的toRadians()方法将给定参数转换为弧度,然后在cos()方法中传递相同的变量)。

  • This method does not throw any exception.

    此方法不会引发任何异常。

Syntax:

句法:

    public static double cos(double d){
    }

Parameter(s):

参数:

double d – A double value (angle) whose cosine value to be found.

double d –要查找其余弦值的双精度值(角度)。

Note:

注意:

  • If we pass "NaN", it returns "NaN".

    如果我们传递“ NaN”,则返回“ NaN”。

  • If we pass an infinity, it returns "NaN".

    如果传递无穷大,则返回“ NaN”。

Return value:

返回值:

The return type of this method is double, it returns the cosine value of the given angle.

此方法的返回类型为double ,它返回给定角度的余弦值。

Java程序演示cos(double d)方法的示例 (Java program to demonstrate example of cos(double d) method)

// Java program to demonstrate the exammple of cos(double d) 
// method of Math Class

class CosMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double d1 = 7.0 / 0.0;
        double d2 = -7.0 / 0.0;
        double d3 = 60.0;

        // Display previous value of d1,d2 and d3
        System.out.println(" Before implementing cos() so the value of d1 is :" + d1);
        System.out.println(" Before implementing cos() so the value of d2 is :" + d2);
        System.out.println(" Before implementing cos() so the value of d3 is :" + d3);

        // By using toRadians() method to convert 
        // absolute value into radians
        d1 = Math.toRadians(d1);
        d2 = Math.toRadians(d2);
        d3 = Math.toRadians(d3);

        // Here , we will get (NaN) because we are passing 
        // parameter whose value is (infinity)
        System.out.println("After implementing cos() so the value of d1 is :" + Math.cos(d1));

        // Here , we will get (NaN) because we are passing 
        // parameter whose value is (-infinity)
        System.out.println("After implementing cos() so the value of d2 is :" + Math.cos(d2));

        // Here we will find cosine of d3 by using cos() method
        System.out.println("After implementing cos() so the value of d3 is :" + Math.cos(d3));
    }
}

Output

输出量

E:\Programs>javac AtanMethod.java

E:\Programs>java AtanMethod
Before implementing cos() so the value of d1 is :Infinity
Before implementing cos() so the value of d2 is :-Infinity
Before implementing cos() so the value of d3 is :60.0

After implementing cos() so the value of d1 is :NaN
After implementing cos() so the value of d2 is :NaN
After implementing cos() so the value of d3 is :0.5000000000000001


翻译自: https://www.includehelp.com/java/math-class-static-double-cos-double-d-with-example.aspx

java math.cos

你可能感兴趣的:(java,python,jvm,jdk,反射)