Java Math sin() Method

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)

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

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

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

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription