Java Math sin() Method
The sin() method of Java Math class returns the trigonometric sine of the specified angle.
Syntax:
public static double sin(double a)
Parameters:
The parameter ‘a’ represents an angle measured in radians.
Return Value:
The sin() method returns the sine of the argument.
- It returns zero with same sign as argument, if the argument passed is zero.
- It returns NaN, if the argument is NaN or infinity.
Example 1:
public class JavaMathSinExample1 {
public static void main(String[] args) {
double a=30;
//return the sine trigonometric value for a
System.out.println("sine value : "+Math.sin(a));
}
}
Output:
sine value : -0.9880316240928618
Example 2:
public class JavaMathSinExample2 {
public static void main(String[] args) {
//return the sine value for Double.MIN_VALUE
double a=Double.MIN_VALUE;
System.out.println("Sine value for "+a+" = "+Math.sin(a));
}
}
Output:
Sine value for 4.9E-324 = 4.9E-324
Example 3:
public class JavaMathSinExample3 {
public static void main(String[] args) {
// return an Sine value for PI
double x = Math.PI;
System.out.println("sine value for "+x+" = "+Math.sin(x));
}
}
Output:
sine value for 3.141592653589793 = 1.2246467991473532E-16
Example 4:
public class JavaMathSinExample4 {
public static void main(String[] args) {
//returns zero with same sign as argument, if the argument passed is zero
double x= 0d;
System.out.println(Math.sin(x));
}
}
Output:
0.0
Example 5:
public class JavaMathSinExample5 {
public static void main(String[] args) {
//returns NaN, if the argument passed is NaN or infinity
double x= Double.NaN;
System.out.println(Math.sin(x));
}
}
Output:
NaN
