Java Math sin() method with Examples
Last Updated :
28 Jul, 2021
The java.lang.Math.sin() returns the trigonometry sine of an angle in between 0.0 and pi. If the argument is NaN or infinity, then the result is NaN. If the argument is zero, then the result is a zero with the same sign as the argument. The value returned will be between -1 and 1.
Syntax :
public static double sin(double a) ;
Parameter: The value whose sine is to be returned.
Return type: This method returns the sine value of the argument.
Implementation:
Here we will be proposing 2 examples one in which we will simply be showcasing the working of Math.sin() method of java.lang package method and secondary be edge case of the first example specific taken where argument is NaN or infinity.
Example 1
Java
import java.lang.Math;
class Gfg {
public static void main(String args[])
{
double a = 30 ;
double b = Math.toRadians(a);
System.out.println(Math.sin(b));
a = 45 ;
b = Math.toRadians(a);
System.out.println(Math.sin(b));
a = 60 ;
b = Math.toRadians(a);
System.out.println(Math.sin(b));
a = 90 ;
b = Math.toRadians(a);
System.out.println(Math.sin(b));
}
}
|
Output:
0.49999999999999994
0.7071067811865475
0.8660254037844386
1.0
Example 2
Java
import java.lang.Math;
public class GFG {
public static void main(String[] args)
{
double positiveInfinity = Double.POSITIVE_INFINITY;
double negativeInfinity = Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
double result;
result = Math.sin(negativeInfinity);
System.out.println(result);
result = Math.sin(positiveInfinity);
System.out.println(result);
result = Math.sin(nan);
System.out.println(result);
}
}
|
Share your thoughts in the comments
Please Login to comment...