strictmath
StrictMath类cos()方法 (StrictMath Class cos() method)
cos() method is available in java.lang package.
cos()方法在java.lang包中可用。
cos() method is used to return the trigonometric cosine of an angle of the given parameter in the method. Here, cos stands for cosine of an angle.
cos()方法用于返回该方法中给定参数的角度的三角余弦值 。 在这里,cos代表一个角度的余弦。
cos() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
cos()方法是一个静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出现任何错误。
In this method we pass only radians type argument (i.e. First we convert given argument in radians by using toRadians() method of StrictMath class then after we will pass the same variable in cos() method).
在此方法中,我们仅传递弧度类型的参数(即,首先,我们使用StrictMath类的toRadians()方法将给定的参数转换为弧度,然后在cos()方法中传递相同的变量)。
Syntax:
句法:
public static double cos(double d);
Parameter(s):
参数:
double d – represents the double type value whose trigonometric cosine value to be found.
double d –表示要找到其三角余弦值的double类型值。
Return value:
返回值:
The return type of this method is double – it returns trigonometric cosine value of the given parameter.
此方法的返回类型是双 -返回给定参数的三角余弦值。
Note:
注意:
If we pass NaN as an argument, method returns the same value (NaN).
如果我们将NaN作为参数传递,则方法将返回相同的值(NaN)。
If we pass an infinity, method returns NaN.
如果传递无穷大,则方法返回NaN。
Example:
例:
// Java program to demonstrate the example
// of cos(double d) method of StrictMath Class.
public class Cos {
public static void main(String[] args) {
// variable declarations
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("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
// By using toRadians() method to convert absolute value into radians.
d1 = StrictMath.toRadians(d1);
d2 = StrictMath.toRadians(d2);
d3 = StrictMath.toRadians(d3);
// Here , we will get (NaN) because we are
// passing parameter whose value is (infinity)
System.out.println("StrictMath.cos(d1): " + StrictMath.cos(d1));
// Here , we will get (NaN) because we are
// passing parameter whose value is (-infinity)
System.out.println("StrictMath.cos(d2): " + StrictMath.cos(d2));
// Here we will find cosine of d3 by using cos() method
System.out.println("StrictMath.cos(d3): " + StrictMath.cos(d3));
}
}
Output
输出量
d1: Infinity
d2: -Infinity
d3: 60.0
StrictMath.cos(d1): NaN
StrictMath.cos(d2): NaN
StrictMath.cos(d3): 0.5000000000000001
翻译自: https://www.includehelp.com/java/strictmath-cos-method-with-example.aspx
strictmath