Java中的 StrictMath sin() 方法
Java .lang.StrictMath.sin()是Java中的一个内置函数,它返回一个角度的三角正弦值。
句法:
public static double sin(double ang)
参数:此函数接受单个参数ang ,它是一个双变量,表示函数将返回其三角正切的角度(以弧度为单位)。
返回值:此方法返回作为参数传递给函数的角度的正弦值。考虑以下情况:
- 如果参数是NaN或infinity ,则函数返回NaN 。
- 如果参数为零,则函数返回零,其符号与参数的符号相同。
例子:
Input : ang = 0.5235987755982988(30 degree)
Output : 0.49999999999999994
Input : ang = 0.7853981633974483(45 degree)
Output : 0.7071067811865475
下面的程序说明了Java.lang.StrictMath.sin()函数在Java中的工作:
方案一:
// Java Program to illustrate sin()
import java.io.*;
import java.math.*;
import java.lang.*;
class GFG {
public static void main(String[] args)
{
double ang = (60 * Math.PI) / 180;
// Display the trigonometric sine of the angle
System.out.println("Sine value of 60 degrees : "
+ StrictMath.sin(ang));
}
}
输出:
Sine value of 60 degrees : 0.8660254037844386
方案二:
// Java Program to illustrate sin()
import java.io.*;
import java.math.*;
import java.lang.*;
class GFG {
public static void main(String[] args)
{
double ang = 77.128;
// Convert the angle to its equivalent radian
double rad = StrictMath.toRadians(ang);
System.out.println(rad);
// Display the trigonometric sine of the angle
System.out.println("Sine value of 77.128 degrees : "
+ StrictMath.sin(rad));
}
}
输出:
1.3461375454781863
Sine value of 77.128 degrees : 0.9748701783788553
参考: https: Java/lang/StrictMath.html#sin()