×

Java Math tan() Method

The tan() method of Java Math class returns the trigonometric tangent of the specified angle.

Syntax:

public static double tan(double a)

Parameters:

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

Return Value:

The tan() method returns the tangent 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 JavaMathTanExample1 {
    public static void main(String[] args) {
        double a=30;
        //return the tangent value for a
        System.out.println("Tangent value: "+Math.tan(a));
    }
}

Output:

Tangent value: -6.405331196646276

Example 2:

public class JavaMathTanExample2 {
    public static void main(String[] args) {
        //return the tangent value for Double.MIN_VALUE
        double a=Double.MIN_VALUE;
        System.out.println("Tangent value for "+a+" = "+Math.tan(a));
    }
}

Output:

Tangent value for 4.9E-324 = 4.9E-324

Example 3:

public class JavaMathTanExample3 {
    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("Tangent value for "+x+" = "+Math.atan(x));
    }
}

Output:

Tangent value for -0.0 = -0.0

Example 4:

public class JavaMathTanExample4 {
    public static void main(String[] args) {
        //return a tangent value for infinity
        double x = -6/0.0d;
        System.out.println("Tangent value for "+x+" = "+Math.tan(x));
    }
}

Output:

Tangent value for -Infinity = NaN

Example 5:

public class JavaMathTanExample5 {
    public static void main(String[] args) {
        //return a tangent value for Nan
        double x = Double.NaN;
        System.out.println("Tangent value for "+x+" = "+Math.tan(x));
    }
}

Output:

Tangent value for NaN = NaN

Related Topics

Java Integer shortValue() method

The shortValue() method of Java Integer class returns a short value for this Integer after a narrowing primitive conversion. Syntax public short shortValue () Parameters NA Overrrides: The shortValue () overrides : shortValue in class Number  Return Value This...

1 minute read.

Java Math getExponent() Method

The getExponent() method of Math class returns the unbiased exponent of the argument. Syntax: public static int getExponent (double d) Parameters: The parameter ‘d’ represents the double value. Return Value: The getExponent () method returns the...

1 minute read.

Ganesha’s Pattern in Java

This part teaches us how to use stars and other special characters to write Ganesha's Pattern in Java programming. Among the most challenging Java pattern applications to code. The Ganesha will be...

3 minutes read.

Java Math nextAfter() Method

The nextAfter() method of Math class returns the floating-point value adjacent to the first argument in direction of the second argument. Syntax: public static double nextAfter (double start, double direction)public static float...

2 minutes read.

Minimum Number of Platforms Required for a Railway Station

The train station problem is one of the most significant problems typically posed in the programming round interview to gauge a candidate's aptitude for logic and problem-solving. Problem of Railway Station The...

6 minutes read.

Java Boolean parseBoolean() Method

The parseBoolean() method of Boolean class returns a Boolean value for the specified String argument. It returns true if and only if string’s value is equal to “true”, else it...

1 minute read.

Java Solid Principles

Java implements the object-oriented SOLID principles for the design of software architecture. Solid Principles Java implements the object-oriented SOLID principles for the design of software architecture.   Five guiding principles transformed...

4 minutes read.

For Loop Program in Java

For Loop Program in Java The for-loop program in Java is written when we want a particular set of statements to be executed repeatedly until the given criteria/ condition is met....

8 minutes read.

Java extend multiple classes

In Java, what does extend mean? One of several Java inheritance keywords is extended, meaning we pass all or most of the Parent class's characteristics through to the Child class. The...

3 minutes read.

Java Integer valueOf() method

The valueOf() method of Java Integer class returns an Integer object holding the specified int value. The second method returns an Integer object holding the specified String value. The third syntax returns...

2 minutes read.

Enum Java Interview Questions

1. What exactly is Java? Java is a portable, high-level, object-oriented, robust, secure, platform-independent, multi-threaded, high-performance programming language. Developed in June 1991 by James Gosling, also known as Platform. 2. Enum is...

3 minutes read.

Java Framework List

The framework is the programs which are written in Java. Frameworks in Java are used to create web applications. The code which can reuse can act as a reference for...

6 minutes read.

Matrix Multiplication in Java

In Java, using the binary operator (*) we can perform matrix multiplication. A Matrix is a group of arrays. In the multiplication of matrices, the elements of each row are...

3 minutes read.

Interchange Diagonal elements in Java

In this article, you will be very well acknowledged about what is a matrix with an example. You will also be acknowledged about how to interchange the diagonal elements in...

4 minutes read.

What is anagram in Java?

In this section will explain what an anagram is in Java and demonstrate how to determine whether or not a text is an anagram. In Java interviews, the anagram Java...

4 minutes read.

Java SE vs EE

Java : Java is an independent platform. It works on any kind of operating system. We use java to develop and to focus on large or major projects. The goal of...

3 minutes read.

How to Iterate a HashMap in Java?

Hash-map is a class of Java collections framework which has the functionality to implement the Map interface of Java. It stores the data in key-value pairs and can be accessed...

5 minutes read.

Sum of digits in string in java

To find the sum of all digits in a string, you need to traverse through the string one by one character; if the character is an integer, you need to...

2 minutes read.

Differences between Set and List in Java

Set in Java: The Java. util package contains an interface called the set. The set interface expands the Collection interface. A collection interface is an unordered collection of List where duplicates...

6 minutes read.

If Condition in Lambda Expression Java

The new and significant lambda expression feature of Java was added in Java SE 8. It provides a clear and concise mechanism for describing a single-method interface using an expression....

4 minutes read.