Java Math - sin() Method
The java.lang.Math.sin() method returns trigonometric sine of an angle (angle should be in radians). In special cases it returns the following:
- If the argument is NaN or an infinity, then the result is NaN.
- If the argument is zero, then the result is a zero with the same sign as the argument.
In the graph below, sin(x) vs x is plotted.
Syntax
public static double sin(double a)
Parameters
a |
Specify the angle in radian. |
Return Value
Returns the trigonometric sine of an angle.
Exception
NA.
Example:
In the example below, sin() method is used to find out the trigonometric sine of an angle.
import java.lang.*; public class MyClass { public static void main(String[] args) { System.out.println(Math.sin(Math.PI/6)); System.out.println(Math.sin(Math.PI/4)); System.out.println(Math.sin(Math.PI/3)); } }
The output of the above code will be:
0.49999999999999994 0.7071067811865475 0.8660254037844386
❮ Java.lang - Math