×

Java Math tanh() Method

The tanh() method of Java Math class returns the hyperbolic tangent of the specified double value.

Syntax:

public static double tanh(double x)

Parameters:

The parameter ‘x’ represents the number whose hyperbolic tangent is to be determined.

Return Value:

The tanh() method returns the hyperbolic tangent of the argument.

  • It returns zero with same sign as argument, if the argument passed is zero.
  • It returns +1.0, if the argument is positive infinity.
  • It returns -1.0, if the argument is negative infinity.
  • It returns NaN, if the argument is NaN.

Example 1:

public class JavaMathTanhExample1 {
    public static void main(String[] args) {
        double a=30;
        //return the hyperbolic tangent value for a
        System.out.println("Hyperbolic tangent value : "+Math.tanh(a));
    }
}

Output:

Hyperbolic tangent value : 1.0

Example 2:

public class JavaMathTanhExample2 {
    public static void main(String[] args) {
        //returns +1.0, if the argument is positive infinity
        double a=Double.POSITIVE_INFINITY;
        System.out.println("Hyperbolic tangent value for "+a+" = "+Math.tanh(a));
    }
}

Output:

Hyperbolic tangent value for Infinity = 1.0

Example 3:

public class JavaMathTanhExample3 {
    public static void main(String[] args) {
        //returns -1.0, if the argument is negative infinity
        double a=Double.NEGATIVE_INFINITY;
        System.out.println("Hyperbolic tangent value for "+a+" = "+Math.tanh(a));
    }
}

Output:

Hyperbolic tangent value for -Infinity = -1.0

Example 4:

public class JavaMathTanhExample4 {
    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("Hyperbolic tangent value for "+x+" = "+Math.tanh(x));
    }
}

Output:

Hyperbolic tangent value for -0.0 = -0.0

Example 5:

public class JavaMathTanhExample5 {
    public static void main(String[] args) {
        //return NaN, if the argument passed is NaN
        double x = Double.NaN;
        System.out.println("Hyperbolic tangent value for "+x+" = "+Math.tanh(x));
    }
}

Output:

Hyperbolic tangent value for NaN = NaN

Related Topics

Java Implements Keyword

To understand about the keyword implements we need to learn about the concept of the interfaces and inheritance in java programming languages. So let us learn about the interface and...

3 minutes read.

Best Java IDE

Applications for desktop, workplace, smartphone, and the internet can be created using Java, one of the most popular programming languages. Java will undoubtedly be a popular programming language for so...

5 minutes read.

Java Snippets

The term "snippet" refers to a section of code that addresses numerous issues with just a few lines of code. Decreases the number of lines of code and improves programmer...

3 minutes read.

Activity selection problem in Java

The activity selection problem is a multiple objective problem hat requires choosing non-conflicting tasks to complete within a specific amount of time from a list of tasks identified by a...

5 minutes read.

Difference Between Java and PHP

The two most used programming languages are PHP and Java. Both of them have a lot of similarities and distinctions. Let's first grasp each of them individually before examining their...

3 minutes read.

Flag Pattern in Java

The flag pattern in Java can be printed, which will be covered in this part. Given how difficult they are to code, flag patterns are rarely asked by interviewers. We separate...

2 minutes read.

Alien language problem in Java

Given the alphabetic sequence of an alien language, given a sorted dictionary (array of words) for the languages. Example: Words = { "aac", "abc", "aaa" } Output c, a, b Algorithm: (1) Compare two words that...

3 minutes read.

Java Session

Session indicates interval of time. A session is a simple  time interval in which servers and client interacts. To maintain the state of the client or user we use technologies...

5 minutes read.

Contextual keywords in Java

Contextual keywords were earlier known as restricted identifiers and restricted keywords. Context keywords are chosen based on their expected placement in the syntactic grammar. These are the keywords in the code...

3 minutes read.

Object Oriented Programming (OOPs)

Since the dawn of earth, we have kept on evolving. The need for evaluation comes with the aim of improving the existing systems when something inappropriate is found for the...

5 minutes read.

Fork Join in Java

Multithreaded processors are being introduced in new computer systems today. The operation is faster due to multicore CPUs. Therefore, it becomes essential for a programmer to leverage multithreaded processors effectively...

4 minutes read.

Sleeping Barber Problem in Java

The barbershop in this issue has one barber, one barber chair, and N chairs for customers in the waiting area. We may demonstrate the issue by keeping with the original...

6 minutes read.

Java Destructors

Before knowing about Java destructors, let us know about constructors. If we understand the concept of the constructor, we can easily understand about destructor and also, we will get an...

3 minutes read.

Bouncy Number in Java

We will define bouncy numbers in this section and write Java programmes to determine whether a specific number is bouncy. Java coding exams and academic assignments usually inquire about the...

3 minutes read.

Java Double Keyword

In java primitive data types, we have two different types of data types which are Boolean and floating-point data types.In floating data type again we have four types which are...

3 minutes read.

Minimum XOR value pair in Java

In this section, you will discuss about minimum XOR value pair in Java. The objective is to enforce a value that indicates the least XOR values of the two numbers from...

4 minutes read.

CRC Program in Java

The acronym CRC stands for Cyclic Redundancy Check. It is invented by W. Wesley Peterson in 1961. It is an error detection technique that detects errors in digital networks (also...

5 minutes read.

Java List Implementations

ArrayList and LinkedList are the two implementations of List that are for general-purpose. You'll probably utilise an array list the majority of the time because it's quick and provides constant-time...

3 minutes read.

How to add Elements in Array in Java

Consider an array of the size n, in the given size we must add the elements in the given array. In this tutorial we are preferred to learn how to add...

3 minutes read.

Java inheritance with Example

Java inheritance Java inheritance is a mechanism in which a child object acquires all the properties and behaviors of a parent object. It helps in reusing the code and establishes...

7 minutes read.