Java Math tanh() Function

tanh function in java

Java Math Class

Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs(), tanh Function etc.
The java.lang.Math class contains various methods for performing basic numeric operations

Here, in the page we will discuss about the tanh Function of Math class in java.

Java cosh Function :

Java Collection contains Math class and The class Math contains methods for performing basic and advance numeric operations such as the exponential, logarithm, square root, and trigonometric functions.
The tanh Function of math class in Java returns the hyperbolic tangent of the input angle. It is a static function so we can access it by using the Math class.

Syntax:

Math.tanh(number);

Definition of Parameters:

Return Type :

  • For positive or negative number, It returns hyperbolic tangent value.
  • For 0 as argument, It will return 0.
  • For + Infinity, It will return +1.
  • For Infinity, It will return -1.
  • For NaN argument, this method will return NaN.

Example :

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing variables in Degree
        int a = 0;
        int b = 60;
        
        // Using tanh Function
        double tanha = Math.tanh(a);
        double tanhb = Math.tanh(b);
        
        // Printing Values of Variables
        System.out.println("tanh Value For angle a : " + tanha);
        System.out.println("tanh Value For angle b : " + tanhb);
    }
}
Output:

tanh Value For angle a : 0.0
tanh Value For angle b : 1.0

In the above Example, We had taken two variables with two different angles stored in them. we need to store the hyperbolic tangent values of the given angles in variables of double data type.

Example:

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing variables in Degree
        int a = 0;
        int b = 60;

        // converting variables to radians
        double radiana = Math.toRadians(a);
        double radianb = Math.toRadians(b);

        // printing tangent values
        System.out.println("tan value of a : " + Math.tanh(radiana));
        System.out.println("tan value of b : " + Math.tanh(radianb));
    }
}
Output:

tan value of a : 0.0
tan value of b : 0.7807144353592677

In the above Example, We had converted the given angle into radians because  as per the official documentation of Java, the tanh() method takes the angle as radians.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription