当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java StrictMath cos()用法及代码示例


java.lang.StrictMath类的所有方法:Set 1,Set 2

java.lang.StrictMath.cos()是Java中的内置方法,用于返回给定角度的余弦值。当给定参数为NaN或无穷大时,该方法返回NaN。

用法:


public static double cos(double num)

参数:该方法接受一个双精度类型的参数num,并以弧度表示要返回余弦值的角度。

返回值:该方法返回参数的余弦值。
Examples:

Input:num = 62.0
Output:0.6735071623235862

Input:num = 64.6
Output:-0.19607204956188945

下面的程序演示了java.lang.StrictMath.cos()方法:
程序1:

// Java praogram 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);} 
}
输出:
The cosine of 0.0 = 1.0
The cosine of 1.0 = 0.5403023058681398
The cosine of 64.6 = -0.19607204956188945

程序2:

// Java praogram 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


相关用法


注:本文由纯净天空筛选整理自ankita_chowrasia大神的英文原创作品 StrictMath cos() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。