Java Number类

描述

java.lang.Math.acos(double a) 返回角度的反余弦值,范围为 0.0 到 pi。

如果参数为 NaN 或其绝对值大于 1,则结果为 NaN。

结果必须在正确舍入结果的 1 ulp 范围内。结果必须是半单调的。

声明

语法

public static double acos(double d)

参数

这里是参数的详细信息 -

  • d - 双精度数据类型。

返回值

  • 此方法返回指定 double 值的反余弦。

示例 1

在此例如,我们展示了如何使用 Math.acos() 方法来获取双精度数的 acos。我们创建了一个双精度变量 x 并用给定的角度初始化它。然后使用 Math.toRadians() 方法检索弧度,然后使用 Math.acos() 方法打印 acos 值。

public class Test {
   public static void main(String args[]) {
      double degrees = 45.0;
      double radians = Math.toRadians(degrees);

      System.out.format("The value of pi is %.4f%n", Math.PI);
      System.out.format("The arccosine of %.1f degrees is %.4f%n", degrees, Math.acos(radians));
   }
}

这将产生以下结果 -

输出

The value of pi is 3.1416
The arccosine of 45.0 degrees is 0.6675

示例 2

在此示例中,我们将展示如何使用 Math.acos() 方法来获取浮点数的 acos。我们创建了一个浮点变量 x 并用给定的角度初始化它。然后使用 Math.toRadians() 方法检索弧度,然后使用 Math.acos() 方法打印 acos 值。

public class Test {
   public static void main(String args[]) {
      float degrees = (float)45.0;
      double radians = Math.toRadians(degrees);

      System.out.format("The value of pi is %.4f%n", Math.PI);
      System.out.format("The arccosine of %.1f degrees is %.4f%n", degrees, Math.acos(radians));
   }
}

这将产生以下结果 -

输出

The value of pi is 3.1416
The arccosine of 45.0 degrees is 0.6675

示例 3

在此示例中,我们将展示如何使用 Math.acos() 方法来获取零值的 cos。我们创建了一个浮点变量 x 并使用给定角度将其初始化为零值。然后使用 Math.toRadians() 方法检索弧度,然后使用 Math.acos() 方法打印 acos 值。

public class Test {
   public static void main(String args[]) {
      float degrees = (float)0.0;
      double radians = Math.toRadians(degrees);

      System.out.format("The value of pi is %.4f%n", Math.PI);
      System.out.format("The arccosine of %.1f degrees is %.4f%n", degrees, Math.acos(radians));
   }
}

这将产生以下结果 -

输出

The value of pi is 3.1416
The arccosine of 0.0 degrees is 1.5708