Java Math acos()方法及实例

来源:这里教程网 时间:2026-02-17 20:56:54 作者:

Java Math acos()方法及实例

java.lang.Math.acos()返回0.0和π之间的角度的弧形余弦。弧形余弦也被称为余弦的逆值。如果参数为NaN或其绝对值大于1,则结果为NaN。

语法:

public static double acos(double a)

参数:
a:要返回其弧形余弦的值。
返回。
该方法返回参数的弧形余弦。

例子:展示java.lang.Math.acos()方法的工作。

// Java program to demonstrate working// of java.lang.Math.acos() methodimport 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));    }}

输出。

NaN1.51593767945364540.01.57079632679489663.141592653589793NaN

相关推荐