×

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

Difference between String Tokenizer and split Method in Java

Introduction Today, let us understand the difference between String Tokenizer and Split Method. First, let us learn about the String Tokenizer and Split method individually and then know about their differences String...

7 minutes read.

Memory Areas in Java

Let’s have a look at how memory management in Java works. We will be going to discuss how the objects get destroyed, the working of a garbage collector, and things...

5 minutes read.

Bucket Sort in Java

Bucket Sort in JavaBucket sort is also called bin sort. Bucket sort first puts the elements of the array or list into different buckets. The first bucket contains elements of the smallest value. The...

11 minutes read.

Intersection Point of two linked list in Java

In this article, you will be very well acknowledged about how to achieve the intersection point of two linked list in Java. There are several approaches to obtain. Surely each...

8 minutes read.

Morris Traversal for Preorder in Java

Without the use of recursion or stacks, we traverse a tree using the Morris algorithm. The linked binary tree is the foundation of the Morris traversal. Preorder Morris Traversal Algorithm The preorder...

3 minutes read.

Concurrent Modification Exception In Java

When an object is attempted to be updated concurrently when it is not allowed, the ConcurrentModificationException arises. This error typically occurs while using Java Collection classes. When another thread is iterating...

5 minutes read.

How to use Lambda Expression in 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...

4 minutes read.

How to Calculate Week Number From Current Date in Java?

The WeekFields class's weekOfMonth() method is utilized to return the field for access the week of a month based on this WeekFields. If the first day of the month is a...

3 minutes read.

Ramanujan Number or Taxicab Number in Java

In this section, we will discuss what a Ramanujan number (also known as a Hardy-Ramanujan number) is and how to use a Java programme to determine if a given integer...

3 minutes read.

Java LinkedList vs ArrayList

LinkedList In LinkedList, each element is a distinct entity containing an information portion and an address component, and the elements are not kept in consecutive locations. Pointers & addresses are used...

3 minutes read.

How to create a linked list in Java

Introduction: The linked listing is one type of linear statistics shaped like an array. Not like arrays, linked listing factors aren't stored in a contiguous place. The elements have linked...

3 minutes read.

Differences between Byte Code and Machine Code

This tutorial will discuss the differences between Byte Code and Machine Code. Before that, let's try to know what byte and machine code is. Introduction Every computer has a set of instructions...

4 minutes read.

Balanced Prime Number in Java

This section will cover the definition of a balanced prime number as well as how to find one using a Java program. Balance Prime Number A prime number that is equivalent to...

5 minutes read.

Type Annotations in Java

Only declarations were eligible for annotations in earlier versions of Java. With Java 8, you may now annotate any type use, including types in declarations, generics, and casts: @Encrypted String data; List<@NonNull...

6 minutes read.

Java String trim() method

Java String trim() method returns String after eliminating leading and trailing spaces. Note:- Java String trim() method doesn't trim or omit middle spaces. Syntax: public String trim() Returns: It returns string with omitted leading and...

2 minutes read.

Java Transient

Java Transient In Java, Serialization is used to convert an object into a stream of the byte. The byte stream consists of the data of the instance as well as the...

3 minutes read.

Java Single Linkedlist

Like arrays, linked lists are a type of linear data structure. Unlike arrays, which store each element in the same location, linked lists employ pointers to connect the elements together. In...

25 minutes read.

Advantages and Disadvantages of Strings in Java

What is a String? Java is an object-oriented, platform-independent, high-level, general-purpose, and interpreted programming language.Sun Microsystems is known as the founder of java in 1991; the Java programming language was developed...

4 minutes read.

How to Send SMS in Java with Example

Sending SMS messages in Java is a fairly common task, and there are a number of libraries and APIs available to help you do it. One popular option is to...

2 minutes read.

Java IO file not found exception

One of the exception classes offered by the java.io package is FileNotFoundException. An exception is raised when we attempt to access a file that isn't present in the system. It...

4 minutes read.