當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。