English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
Java Math atan()方法返回指定值的反正切值。
反正切是正切函数的反函数。
atan()方法的语法为:
Math.atan(double num)
num - 要返回其反正切函数的数字
返回指定数字的反正切
如果指定值为零,则返回0
如果指定的数量是NaN,返回NaN
Note:返回值是 -pi / 2 到 pi / 2 之间的角度。
import java.lang.Math; class Main { public static void main(String[] args) { //Create a variable double a = 0.99; double b = 2.0; double c = 0.0; //Print the arctangent value System.out.println(Math.atan(a)); // 0.7803730800666359 System.out.println(Math.atan(b)); // 1.1071487177940904 System.out.println(Math.atan(c)); // 0.0 } }
In the above example, we have imported the java.lang.Math package. This is important if we want to use the methods of the Math class. Note the expression
Math.atan(a)
In this case, we have used the class name to call the method. This is because atan() is a static method.
import java.lang.Math; class Main { public static void main(String[] args) { //Create a variable //Square root of a negative number //The result is not a number (NaN) double a = Math.sqrt(-5); //Print the arctangent value System.out.println(Math.atan(a)); // NaN } }
In this case, we have created a variable named a.
Math.atan(a) - Returns NaN because a negative number (-5) is not a number
Note: We have already usedJava Math sqrt()A method to calculate the square root of a number.