×

Java Math sin() Method

The sin() method of Java Math class returns the trigonometric sine of the specified angle.

Syntax:

public static double sin(double a)

Parameters:

The parameter ‘a’ represents an angle measured in radians.

Return Value:

The sin() method returns the sine of the argument.

  • It returns zero with same sign as argument, if the argument passed is zero.
  • It returns NaN, if the argument is NaN or infinity.

Example 1:

public class JavaMathSinExample1 {
    public static void main(String[] args) {
        double a=30;
        //return the sine trigonometric value for a
        System.out.println("sine value : "+Math.sin(a));
    }
}

Output:

sine value : -0.9880316240928618

Example 2:

public class JavaMathSinExample2 {
    public static void main(String[] args) {
        //return the sine value for Double.MIN_VALUE
        double a=Double.MIN_VALUE;
        System.out.println("Sine value for "+a+" = "+Math.sin(a));
    }
}

Output:

Sine value for 4.9E-324 = 4.9E-324

Example 3:

public class JavaMathSinExample3 {
    public static void main(String[] args) {
        // return an Sine value for PI
        double x = Math.PI;
        System.out.println("sine value for "+x+" = "+Math.sin(x));
    }
}

Output:

sine value for 3.141592653589793 = 1.2246467991473532E-16

Example 4:

public class JavaMathSinExample4 {
    public static void main(String[] args) {
       //returns zero with same sign as argument, if the argument passed is zero
        double x= 0d;
       System.out.println(Math.sin(x));
    }
}

Output:

0.0

Example 5:

public class JavaMathSinExample5 {
    public static void main(String[] args) {
       //returns NaN, if the argument passed is NaN or infinity
        double x= Double.NaN;
       System.out.println(Math.sin(x));
    }
}

Output:

NaN

Related Topics

Thread Synchronization in Java

In Java, the smallest processing component is a thread, which is a small subprocess. It follows a different course of action. Threads are autonomous. If an exception occurs in one thread,...

6 minutes read.

Java LDAP Authentication

WHAT IS LDAP? Clients can communicate with directory services by sending requests and receiving responses using the Lightweight Directory Access Protocol (LDAP). The term "LDAP server" refers to a directory service...

7 minutes read.

Stock Span Problem Using Stack in Java

The stock span problem is an issue in finance where we must determine a stock’s price span over all N days given a set of N daily price quotes. The...

6 minutes read.

How to calculate time complexity of any program in Java

Java : Java's syntax and principles are derived from the C and C++ languages. We know that java is one of the programming language. The main feature of java which is...

3 minutes read.

Creating API Document Javadoc tool

The JavaDoc utility is a document generator tool written in Java that generates standard documentation in HTML format. It parses declarations and documentation in a source file collection that describes...

3 minutes read.

How to Set Environment Variables for Java

Introduction Java is an object-oriented programming language that is based on classes and can be employed mostly to develop web and desktop applications. No matter the computer architecture, Java applications are...

7 minutes read.

Java Integer compareUnsigned() method

The compareUnsigned() method of Integer class compares two int objects numerically by treating the values as unsigned. Syntax public static int compareUnsigned(int x , int y) Parameters The parameters ‘x’ and ‘y’ represent the...

1 minute read.

Java Developer

Who is a Java Developer? A Java developer is a skilled programmer who works on commercial applications, software, and webpages.  Java developers can work in two different areas: Operating system development:...

3 minutes read.

Java vs Golang

Java Java is both a programming language and a platform. Java is a high-level, dependable, object-oriented, and secure programming language. Java was developed in 1995 by Sun Microsystems, which is now an...

4 minutes read.

What is string in Java why it's immutable

String in Java Strings are a series of characters commonly used in Java language, which are considered objects in the Java. To create and manipulate strings, java will provide the String...

4 minutes read.

Methods in Java

The Methods in Java are the collection of statements that are executed when the method is called. By using the methods, the complexity of writing the code decreases. The method consists...

4 minutes read.

Salesman Problem in Java

The Traveling Salesman Problem determines the shortest path that visits each city approximately once and loops back to the starting location. Another Java problem that is most like the Traveling...

5 minutes read.

Compile time vs Runtime in java

Introduction: This article will discuss compile time vs. runtime in java. Compile time and runtime are two programming terms utilized in software improvement. Compile time is when the source code is...

3 minutes read.

Java Generate Random String

Java Generate Random String In this tutorial, we will learn about to generate random string in Java. Random generation strings mean any string will be generated, which does not follow any...

7 minutes read.

Set Matrix Zeros in Java

In coding round interviews, it is frequently asked as the most significant challenge. an m*n matrix is provided. Set the entire column and row of the matrix to 0 if any...

6 minutes read.

What is Core Java?

The fundamental Java, which includes the fundamental idea of the Java programming language, is referred to as "Core Java." The definition of "Core" is the core idea of something. Core...

3 minutes read.

How to download and install Eclipse in Windows?

Download and Install Eclipse on Windows Eclipse is an open source IDE (Integrated Development Environment) which is used to help the programmers to provide a platform to write and run the...

1 minute read.

Diamond problem in Java

The Diamond Problem in Java is connected to multiple inheritances. It is also referred to as the "deadly diamond dilemma" or even the "deadly diamond of death”. The solution for...

5 minutes read.

Java String toCharArray() method

Java String toCharArray() method converts current String into character array. Syntax: public char[] toCharArray() Returns: It returns a character array Java String toCharArray() method example 1 import java.util.Arrays; public class JavaStringToCharArrayEx1 {           public static...

2 minutes read.

Java Math log() Method

The log() method of Math class returns the natural logarithmic value for the specified double argument. Syntax: public static double log(double a) Parameters: The parameter ‘a’ represents the value. Return Value: The log() method returns the...

1 minute read.