反正弦是正弦函数的反函数。
asin()
方法的语法是:
Math.asin(double num)
这里,
asin()
是一个静态方法。因此,我们使用类名访问该方法,
Math
。
asin() 参数
asin()
方法接受一个参数。
注意: num 的绝对值应始终小于 1、
asin() 返回值
返回指定数字的反正弦 如果指定值为零则返回 0 如果指定的数字是NaN
或大于 1,则返回 NaN
注意: 返回值是-pi/2 到 pi/2 之间的角度。
示例 1: Java Math asin()
import java.lang.Math; class Main { public static void main(String[] args) { // create variable double a = 0.99; double b = 0.71; double c = 0.0; // print the arcsine value System.out.println(Math.asin(a)); // 1.4292568534704693 System.out.println(Math.asin(b)); // 0.7812981174487247 System.out.println(Math.asin(c)); // 0.0 } }
在上面的例子中,我们导入了
java.lang.Math
包。如果我们想使用
Math
类的方法,这很重要。注意表达式,
Math.asin(a)
这里,我们直接使用了类名来调用方法。这是因为
asin()
是一个静态方法。
示例 2: Math asin() 返回 NaN
import java.lang.Math; class Main { public static void main(String[] args) { // create variable double a = 2; // square root of negative number // results in not a number (NaN) double b = Math.sqrt(-5); // print the arc sine value System.out.println(Math.asin(a)); // NaN System.out.println(Math.asin(b); // NaN } }
这里,我们创建了两个名为
a 和
b 的变量。
Math.asin(a)-返回 NaN,因为 a 的值大于 1
Math.asin(b)-返回 NaN,因为负数(-5) 的平方根不是数字
注意: 我们已经使用 Java Math.sqrt() 方法来计算一个数的平方根。