Java StrictMath asin()方法与示例
StrictMath类asin()方法
asin()方法在java.lang包中可用。
asin()方法用于返回方法中给定参数的反正弦值。在此,asin代表一定角度的反正弦。
asin()方法是静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。
在此方法中,我们仅传递弧度类型的参数(即,首先,我们使用Math类的toRadians()方法将给定的参数转换为弧度,然后在asin()方法中传递相同的变量)。
此方法不会引发任何异常。
在这种方法中,反正弦的含义是给定参数的反正弦或反正弦。
asin()谎言的范围–PI/2至PI/2。
语法:
public static double asin(double d);
参数:
doubled–表示要找到其反正弦值的double类型值。
返回值:
此方法的返回类型为double-返回给定角度的反正弦。
注意:
如果我们将NaN作为参数传递,则方法将返回相同的值(NaN)。
如果我们传递一个绝对值大于1的参数,则方法返回NaN。
示例
//Java程序演示示例
//StrictMath类的asin(doubled)方法的说明。
public class Asin {
public static void main(String[] args) {
//变量声明
double a1 = 100;
double a2 = Math.PI / 2;
double a3 = 0;
//显示a1,a2和a3的先前值
System.out.println("a1: " + a1);
System.out.println("a2: " + a2);
System.out.println("a3: " + a3);
//在这里,我们将获得NaN,因为我们
//传递参数的绝对值为
//大于1-
System.out.println("StrictMath.asin(a1): " + StrictMath.asin(a1));
//通过使用toRadians()方法用于转换
//绝对弧度
a2 = StrictMath.toRadians(a2);
//以弧度形式显示a2的值
System.out.println("StrictMath.toRadians(a2): " + a2);
//找到a2的反正弦
System.out.println("StrictMath.asin(a2): " + StrictMath.asin(a2));
//在这里,我们将得到0,因为我们正在传递
//绝对值为0的参数
System.out.println("StrictMath.asin(a3): " + StrictMath.asin(a3));
}
}输出结果
a1: 100.0 a2: 1.5707963267948966 a3: 0.0 StrictMath.asin(a1): NaN StrictMath.toRadians(a2): 0.027415567780803774 StrictMath.asin(a2): 0.02741900326072046 StrictMath.asin(a3): 0.0