English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math mathematical methods
Java Math acos()方法返回指定值的反余弦值。
反余弦是余弦函数的反函数。
acos()方法的语法为:
Math.acos(double num)
num - 要返回其反余弦的数字,它应始终小于1。
返回指定数字的反余弦值
如果指定数是NaN或大于1,返回NaN
Note:返回值是介于0.0 à pi entre les angles.
import java.lang.Math; class Main { public static void main(String[] args) { //Create variables double a = 0.5; double b = 0.79; double c = 0.0; //Print the inverse cosine value System.out.println(Math.acos(a)); // 1.0471975511965979 System.out.println(Math.acos(b)); // 0.6599873293874984 System.out.println(Math.acos(c)); // 1.5707963267948966 } }
Dans l'exemple précédent, nous avons importé le paquet java.lang.Math. Si nous devons utiliser les méthodes de la classe Math, c'est très important. Notez l'expression
Math.acos(a)
Here, we directly used the class name to call the method. This is because acos() is a static method.
import java.lang.Math; class Main { public static void main(String[] args) { //Create variables double a = 2; //The square root of a negative number. //The result is not a number (NaN) double NaN = Math.sqrt(-5); //Print the inverse cosine value System.out.println(Math.acos(a)); // NaN System.out.println(Math.acos(NaN)); // NaN } }
Here, we created two variables named a and b.
Math.acos(a) - Because the value of a is greater than1, returns NaN.
Math.acos(b) - Because negative numbers (-5). The square root is not a number, returns NaN.
Note: We useMath sqrt()A method to calculate the square root of a number.