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