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


Java Math acos()用法及代碼示例


java.lang.Math.acos()返回介於0.0和pi之間的角度的反餘弦。反餘弦也稱為餘弦的倒數,如果參數為NaN或絕對值大於1,則結果為NaN。

用法:

public static double acos(double a)
參數:
a:the value whose arc cosine is to be returned.
返回:
This method returns the arc cosine of the argument.

例:展示java.lang.Math.acos()方法的用法。


// Java program to demonstrate working 
// of java.lang.Math.acos() method 
import java.lang.Math; 
  
class Gfg { 
  
    // driver code 
    public static void main(String args[]) 
    { 
        double a = Math.PI; 
  
        // Output is NaN, because Math.PI gives 3.141 value 
        // greater than 1 
        System.out.println(Math.acos(a)); 
  
        // convert Math.PI to radians 
        double b = Math.toRadians(a); 
  
        System.out.println(Math.acos(b)); 
  
        double c = 1.0; 
        double d = 0.0; 
        double e = -1.0; 
        double f = 1.5; 
  
        System.out.println(Math.acos(c)); 
        System.out.println(Math.acos(d)); 
        System.out.println(Math.acos(e)); 
   
       // value of f does not lie in between -1 and 1  
       // so output is NaN 
        System.out.println(Math.acos(f)); 
    } 
}

輸出:

NaN
1.5159376794536454
0.0
1.5707963267948966
3.141592653589793
NaN


相關用法


注:本文由純淨天空篩選整理自Niraj_Pandey大神的英文原創作品 Java Math acos() method with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。