java math.acos_Java StrictMath acos()用法及代码示例

java.lang.StrictMath.acos()是一个内置方法,该方法返回给定参数和角度的余弦值。返回的角度在0.0到pi之间的范围内。

注意:如果自变量的绝对值大于1或自变量本身是NaN,则结果也是NaN。

用法:

public static double acos(double num)

参数:该方法接受一个双精度类型的参数num,表示要返回其余弦值的弧。

返回值:该方法返回参数的反余弦值。

例子:

Input: num = 0.45

Output: 1.1040309877476002

Input: num = 8.9

Output: NAN

下面的程序演示了java.lang.StrictMath.acos()方法:

示例1:对于正数

// Java program to illustrate the

// java.lang.StrictMath.acos()

import java.lang.*;

public class Geeks {

public static void main(String[] args)

{

double num1 = 0.65, num2 = 6.30;

// It returns the arc cosine of a value

double acosValue = StrictMath.acos(num1);

System.out.println("The arc cosine value of "+

num1 + " = " + acosValue);

acosValue = StrictMath.acos(num2);

System.out.println("arc cosine value of "+

num2 + " = " + acosValue);

}

}

输出:

The arc cosine value of 0.65 = 0.863211890069541

arc cosine value of 6.3 = NaN

示例2:为负数。

// Java program to illustrate the

// java.lang.StrictMath.acos()

import java.lang.*;

public class Geeks {

public static void main(String[] args)

{

double num1 = -0.65, num2 = -6.30;

// It returns the arc cosine of a value

double acosValue = StrictMath.acos(num1);

System.out.println("The arc cosine value of "+

num1 + " = " + acosValue);

acosValue = StrictMath.acos(num2);

System.out.println("arc cosine value of "+

num2 + " = " + acosValue);

}

}

输出:

The arc cosine value of -0.65 = 2.278380763520252

arc cosine value of -6.3 = NaN


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部