Java Math sin() Method
Java Math Class
Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs() etc.
The java.lang.Math class contains various methods for performing basic numeric operations
Here, in the page we will discuss about the math sin() Method in java.
Java Math sin() Method :
This function returns the trigonometric sine of an angle.
Special Points :
- 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.
Syntax :
public static double sin(double a)
Parameters :
a - an angle, in radians.
Throws Exception :
It does throws any exceptions and error.
Return Value :
The sine of the argument.
Example 1 :
Run
public class Main{ public static void main(String[] args) { double angle = Math.toRadians(30); // convert degrees to radians double sine = Math.sin(angle); // calculate sine of angle System.out.println("Sine of 30 degrees: " + sine); } }
Output :
Sine of 30 degrees: 0.49999999999999994
Explanation :
In this example, we first convert the angle in degrees to radians using the toRadians() method. Then, we pass the angle in radians to the sin() method, which calculates and returns the sine of the angle. Finally, we print the result to the console.
Example 2 :
Run
import java.lang.Math; public class Main { 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); } }
Output :
NaN NaN NaN
Explanation :
In the preceding example, we have observed that :
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.
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.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment