Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
math
math.sin()
communitycreator

# What is Math.sin() in Java? Tarun Telang

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Java has a built-in Math class, defined in the java.lang package, which contains important functions to perform basic mathematical operations. The class has the sin() method, which is used to compute a specified angle’s trigonometric sine.

## Syntax

public static double sin(double angle);


## Parameter

• angle represents the double value corresponding to the angle in radians, of which we have to find the sine.

## Return value

• The function returns the double value corresponding to the trigonometric sine of the angle.

If the value of angle is infinity or NaNnot a number, then the returned value is NaN.

## Code

To convert an angle measured in degrees to an equivalent angle measured in radians, we can use the built-in method Math.toRadians(double angle_in_degrees).

import java.lang.Math;class HelloWorld {    public static void main( String args[] ) {        double param = Math.toRadians(30);        double result = Math.sin(param);        System.out.println("sin(" + param + ") = " + result);                param = Math.toRadians(45);        result = Math.sin(param);        System.out.println("sin(" + param + ") = " + result);        param = Math.toRadians(60);        result = Math.sin(param);        System.out.println("sin(" + param + ") = " + result);        param = Math.toRadians(90);        result = Math.sin(param);        System.out.println("sin(" + param + ") = " + result);        result = Math.sin(Double.POSITIVE_INFINITY);        System.out.println("sin(∞) = " + result);        result = Math.sin(Double.NaN);        System.out.println("sin(NaN) = " + result);    }}
Example code for Math.sin() in Java

RELATED TAGS

java
math
math.sin()
communitycreator

CONTRIBUTOR Tarun Telang

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 