Java 教程 Java acos() 方法

webster · 2022-05-24 23:07:26 · 热度: 12

acos() 方法用于返回指定 double 类型参数的反余弦值。

语法

double acos(double d)

参数

  • d -- 任何原生数据类型,需要小于 1。

返回值

返回指定 double 类型参数的反余弦值,如果指定的参数大于 1,则返回 NaN。

返回值在 0 到 Math.PI 之间。

实例

以下实例演示了 acos() 方法的使用:

实例

public class CoderctoTest {
    public static void main(String args[]){

        double degrees = 45.0;
        double radians = Math.toRadians(degrees);

        System.out.format("pi 的值为 %.4f%n", Math.PI);
        System.out.format("%.4f 的反余弦值为 %.4f 度 %n", Math.cos(radians), Math.toDegrees(Math.acos(Math.sin(radians))));

    }
}

编译以上程序,输出结果为:

pi 的值为 3.1416
0.7071 的反余弦值为 45.0000 度

实例

public class CoderctoTest {
    public static void main(String[] args) {
        // 变量
        double a = 0.5;
        double b = 0.79;
        double c = 0.0;
        double d = 2;


        // 输出
        System.out.println(Math.acos(a));  // 1.0471975511965979
        System.out.println(Math.acos(b));  // 0.6599873293874984
        System.out.println(Math.acos(c));  // 1.5707963267948966
        System.out.println(Math.acos(d));  // d 大于 1,所以输出 NaN
    }
}

编译以上程序,输出结果为:

1.0471975511965979
0.6599873293874984
1.5707963267948966
NaN

查看更多 Java Number & Math 类 相关内容

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册