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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。