Java StrictMath acos()方法
java.lang.StrictMath.acos() 是一个内置的方法,用于返回给定参数和一个角度的余弦。返回的角度在0.0和 π 之间。
注意: 如果参数的绝对值大于1或者参数本身是NaN,那么结果也是NaN。
语法
public static double acos(double num)
参数: 该方法接受一个参数num,该参数为双倍类型,指的是要返回的弧形余弦。
返回值: 该方法返回参数的弧形余弦。
示例 :
Input: num = 0.45 Output: 1.1040309877476002Input: num = 8.9Output: 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.863211890069541arc 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.278380763520252arc cosine value of -6.3 = NaN
