📜  Java中的 StrictMath cos() 方法及示例

📅  最后修改于: 2022-05-13 01:55:28.703000             🧑  作者: Mango

Java中的 StrictMath cos() 方法及示例

Java.lang.StrictMath 类的所有方法:Set 1, Set 2
Java.lang.StrictMath.cos()是Java中的一个内置方法,用于返回给定角度的余弦值。当给定参数为 NaN 或无穷大时,该方法返回 NaN。
句法:

public static double cos(double num)

参数:该方法接受一个double类型的参数num ,是指要返回其余弦值的弧度角。
返回值:该方法返回参数的余弦。
例子 :

Input: num = 62.0
Output: 0.6735071623235862

Input: num = 64.6
Output: -0.19607204956188945

下面的程序说明了Java.lang.StrictMath.cos() 方法:
方案一:

java
// Java program to illustrate the
// java.lang.StrictMath.cos()
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1 = 0.0, num2= 1.0 , num3= 64.6;
     
    /* Returns trigonometric cosine of specified
    angle in radian*/
    double cosValue = StrictMath.cos(num1);
    System.out.println("The cosine of "+
                           num1+" = " + cosValue);
 
    cosValue = StrictMath.cos(num2);
    System.out.println("The cosine of "+
                           num2+" = " + cosValue);
 
    cosValue = StrictMath.cos(num3);
    System.out.println("The cosine of "+
                           num3+" = " + cosValue);}
}


java
// Java program to illustrate the
// java.lang.StrictMath.cos()
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1= -62.0, num2 = 1.0;
        double num3= (45*(Math.PI))/180;
     
    /* It returns the  cosine of specified
    angle in radian*/
    double cosValue = StrictMath.cos(num1);
    System.out.println("The cosine of "+
                           num1+" = " + cosValue);
    cosValue = StrictMath.cos(num2);
    System.out.println("The cosine of "+
                           num2+" = " + cosValue);
    cosValue = StrictMath.cos(num3);
    System.out.println("The cosine of "+
                           num3+" = " + cosValue);}
}


输出:
The cosine of 0.0 = 1.0
The cosine of 1.0 = 0.5403023058681398
The cosine of 64.6 = -0.19607204956188945

方案二:

Java

// Java program to illustrate the
// java.lang.StrictMath.cos()
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1= -62.0, num2 = 1.0;
        double num3= (45*(Math.PI))/180;
     
    /* It returns the  cosine of specified
    angle in radian*/
    double cosValue = StrictMath.cos(num1);
    System.out.println("The cosine of "+
                           num1+" = " + cosValue);
    cosValue = StrictMath.cos(num2);
    System.out.println("The cosine of "+
                           num2+" = " + cosValue);
    cosValue = StrictMath.cos(num3);
    System.out.println("The cosine of "+
                           num3+" = " + cosValue);}
}
输出:
The cosine of -62.0 = 0.6735071623235862
The cosine of 1.0 = 0.5403023058681398
The cosine of 0.7853981633974483 = 0.7071067811865476