Java Math sin() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.Math

Definition

In Java, Math.sin(a) returns the sine of the angle a. The angle must be in radians, not degrees. Math.sin(Math.PI / 2) is 1.0, and the result always stays between -1.0 and 1.0.

Use it for waves and cycles, for the height of a point on a circle (y = r * sin(angle)), for slopes, and for animation that swings up and down. If your angle is in degrees, convert it with Math.toRadians first.

A static method of the java.lang.Math class, available since the early versions of Java (JDK 1.0). Call it on the class name, as in Math.sin(...). No import is needed, because classes in java.lang are always visible.

Syntax

Pass an angle in radians as a double. The sine comes back as a double.

Java
double top = Math.sin(Math.PI / 2);            // 1.0
double half = Math.sin(Math.toRadians(30));      // about 0.5
double flat = Math.sin(0.0);                     // 0.0
double y = radius * Math.sin(angleInRadians);    // height on a circle
CallWhat it does
Math.sin(Math.PI / 2)A quarter turn: returns 1.0.
Math.sin(Math.toRadians(90))Same angle written in degrees: returns 1.0.
Math.sin(-0.0)Returns -0.0 (zero keeps its sign).
Math.sin(Double.POSITIVE_INFINITY)Returns NaN.

There is only a double version. An int argument widens to double and still means radians: Math.sin(1) is the sine of 1 radian (about 0.8415), not of 1 degree.

Library declarations
Java
// java.lang.Math
public static double sin(double a)

Parameters

ParameterDescription
aThe angle in radians. Smaller number types are widened to double.

Return Value

Return ValueDescription
doubleThe sine of a, a value from -1.0 to 1.0. The result is NaN if a is NaN or an infinity. For a zero argument the result is a zero with the same sign.

Compare with Similar Methods

Sine and its trigonometry neighbours:

MethodHow it differs
cos(a)Cosine: the same wave shifted by a quarter turn, 1.0 at angle 0.
tan(a)Tangent: sine divided by cosine; it has no upper limit.
asin(x)The inverse: finds the angle whose sine is x.
toRadians(deg)Converts degrees to the radians that sin expects.

Java Examples

Example 1 — Radians, Not Degrees: sin(30) Is a Trap

Compare the sine of 30 radians with the sine of 30 degrees, then check two exact landmarks.

Java
import java.util.Locale;

public class MathSinAngles {
    public static void main(String[] args) {
        System.out.println("sin(30) read as radians: " + String.format(Locale.US, "%.4f", Math.sin(30)));
        double thirty = Math.toRadians(30);
        System.out.println("sin(30 degrees) raw:     " + Math.sin(thirty));
        System.out.println("sin(30 degrees) rounded: " + String.format(Locale.US, "%.4f", Math.sin(thirty)));
        System.out.println("sin(PI / 2):             " + Math.sin(Math.PI / 2));
        System.out.println("sin(0.0):                " + Math.sin(0.0));
    }
}

How It Works

  1. 30 is not 30 degrees. Math.sin(30) goes around the circle about 4.8 times (30 radians) and lands on a point with sine -0.9880, nowhere near 0.5.
  2. Convert, then round for display. Math.toRadians(30) is only close to pi/6, so the sine prints as 0.49999999999999994; %.4f shows the expected 0.5000.
  3. Landmarks are exact. The top of the wave, Math.PI / 2, gives exactly 1.0, and a zero angle gives 0.0.

Example 2 — Why sin(PI) Is Not Zero, and Other Special Inputs

See the famous tiny leftover, a safe way to test for "zero", and what negative zero, infinity, and NaN do.

Java
public class MathSinSpecial {
    public static void main(String[] args) {
        double atPi = Math.sin(Math.PI);
        System.out.println("sin(PI) = " + atPi);
        System.out.println("sin(PI) == 0? " + (atPi == 0));
        System.out.println("close to 0? " + (Math.abs(atPi) < 1e-9));
        System.out.println("sin(-0.0) = " + Math.sin(-0.0));
        System.out.println("sin(Infinity) = " + Math.sin(Double.POSITIVE_INFINITY));
        System.out.println("sin(NaN) = " + Math.sin(Double.NaN));
    }
}

How It Works

  1. A tiny leftover. Math.PI misses the true pi by about 1.2E-16, and the sine near pi is almost a straight line, so that error shows up as the answer 1.2246467991473532E-16.
  2. Test with a tolerance. == asks for exact zero and answers false; Math.abs(atPi) < 1e-9 asks "is it practically zero?" and answers true.
  3. No sine for these inputs. Negative zero keeps its sign, but infinity and NaN are not angles on a circle, so the method returns NaN without throwing.

Example 3 — The Height of a Wave Every 30 Degrees

Scale the sine to a wave with amplitude 5 and print its height at six angles.

Java
import java.util.Locale;

public class MathSinWave {
    public static void main(String[] args) {
        double amplitude = 5.0;
        int[] angles = {0, 30, 90, 150, 180, 270};
        for (int deg : angles) {
            double height = amplitude * Math.sin(Math.toRadians(deg));
            System.out.println(String.format(Locale.US, "%3d degrees -> %.2f", deg, height));
        }
    }
}

How It Works

  1. Scale the unit wave. The sine only runs from -1 to 1, so multiplying by amplitude stretches it to a wave that runs from -5 to 5.
  2. A mirror image. 30 and 150 degrees are the same distance from the peak at 90, so both give a height of 2.50.
  3. Rounding hides the noise. At 180 degrees the true height is 0, but the double holds about 6.1E-16; %.2f prints it as 0.00, and 270 degrees reaches the bottom at -5.00.

Frequently Asked Questions

It returns the sine of an angle given in radians, as a double between -1.0 and 1.0. For example, Math.sin(Math.PI / 2) returns 1.0.
Radians. To work with degrees, convert first: Math.sin(Math.toRadians(30)) returns about 0.5, while Math.sin(30) is the sine of 30 radians.
Math.PI is only the double closest to pi, so the sine of it is a tiny leftover, 1.2246467991473532E-16. Round the result or compare it with a small tolerance instead of using ==.
It returns NaN. An infinite angle has no sine, and a NaN input stays NaN. No exception is thrown.
Use Math.asin(x), the inverse of sine. It returns the angle in radians between -PI/2 and PI/2.

Next: sinh()

Hyperbolic sine of a double.

sinh() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful