GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — Java Math sin() method with Examples - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

Java Math sin() method with Examples

Last Updated : 11 Jul, 2025

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
// Java program to demonstrate working
// of java.lang.Math.sin() method
import java.lang.Math;

class Gfg {

    // driver code
    public static void main(String args[])
    {
        double a = 30;
        
        // converting values to radians
        double b = Math.toRadians(a);

        System.out.println(Math.sin(b));

        a = 45;
        
        // converting values to radians
        b = Math.toRadians(a);

        System.out.println(Math.sin(b));

        a = 60;
        
        // converting values to radians
        b = Math.toRadians(a);

        System.out.println(Math.sin(b));

        a = 90;
        
        // converting values to radians
        b = Math.toRadians(a);

        System.out.println(Math.sin(b));
    }
}

Output: 
0.49999999999999994
0.7071067811865475
0.8660254037844386
1.0

 

Example 2  

Java
// Java program to demonstrate working of Math.cos() method
// of java.lang package considering infinity case

// Importing classes from java.lang package
import java.lang.Math;

public class GFG {

    // Main driver method
    public static void main(String[] args)
    {

        double positiveInfinity = Double.POSITIVE_INFINITY;
        double negativeInfinity = Double.NEGATIVE_INFINITY;
        double nan = Double.NaN;
        double result;

        // Here argument is negative infinity,
        // output will be NaN
        result = Math.sin(negativeInfinity);
        System.out.println(result);

        // Here argument is positive infinity,
        // output will also be NaN
        result = Math.sin(positiveInfinity);
        System.out.println(result);

        // Here argument is NaN, output will be NaN
        result = Math.sin(nan);
        System.out.println(result);
    }
}

Output: 
NaN
NaN
NaN

 
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.