×

Java Math cosh() Method

The cosh() method of Math class returns the first hyperbolic cosine((e+e)/2) of a double value.

Syntax:

public static double cosh(double x)

Parameters:

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

Return Value:

The cosh() method returns the hyperbolic cosine of x.

Special cases of the cosh() method are as follows:

  • It returns NaN, is the argument passed is NaN.
  • It returns positive infinity, if the argument passed is infinite.
  • It returns 1.0, if the argument passed is zero.

Example 1:

public class JavaMathCoshExample1 {
    public static void main(String[] args) {
        double a=90;
        //returns the hyperbolic cosine value for a
        System.out.println("Hyperbolic cosine value : "+Math.cosh(a));
    }
}

Output:

Hyperbolic cosine value : 6.102016471589204E38

Example 2:

public class JavaMathCoshExample2 {
    public static void main(String[] args) {
        double a=-0.0d/0.0d;
        //It returns NaN, is the argument passed is NaN
        System.out.println("Hyperbolic cosine value : "+Math.cosh(a));
    }
}

Output:

Hyperbolic cosine value : NaN

Example 3:

public class JavaMathCoshExample3 {
    public static void main(String[] args) {
        // It returns 1.0, if the argument passed is zero
        double x = 0;
        System.out.println("Hyperbolic cosine value : "+Math.cosh(x));
    }
}

Output:

Hyperbolic cosine value : 1.0

Example 4:

public class JavaMathCoshExample4 {
    public static void main(String[] args) {
        // returns positive infinity, if the argument passed is infinite
        double x = 3.0/0.0d;
        System.out.println("1. Hyperbolic cosine value for "+x+":
"+Math.cosh(x));
       // returns positive infinity, if the argument passed is a
negative infinite
        double y = -3.0/0.0d;
        System.out.println("2. Hyperbolic cosine value for "+y+ " :
"+Math.cosh(y));
    }
}

Output:

1.Hyperbolic cosine value for Infinity: Infinity
2.Hyperbolic cosine value for -Infinity : Infinity

Related Topics

How to Change the Day in the Date using Java?

To operate with the date and time in Java, we need the Calendar abstract class. It provides a number of helpful interfaces that enable us to convert dates between a...

4 minutes read.

Union in Java

Sets.union() method in Java returns an immutable representation of both the union of two sets. Every element that is present in either backup set is included in the set that...

2 minutes read.

Static() Function in Java

The static keyword in Java is suitable for variables, constants, and functions. The static keyword is mainly used to control storage so that it may be appropriately used. We shall...

3 minutes read.

Java Program to generate binary numbers

A binary tree can create binary numbers ranging from 1 to n. Every node in a tree, the right, and left nodes, has two children, as is common knowledge. The...

3 minutes read.

Rotate matrix by 90 degrees in Java | Rotate matrix in Java clockwise and anti-clockwise

In this article, you will be acknowledged about what is a matrix along with an example. Most importantly you will be equipped knowledge on how to rotate the matrix by...

4 minutes read.

Hello Program in Java

Hello Program in Java The Hello program in Java displays the word Hello on the console. It is the basic program in Java. In this section, we will learn different ways...

3 minutes read.

Java Static Keyword

It can be either said that static declares the value to be the same, not only in the instance of a class but also as the whole. To declare a variable...

6 minutes read.

Maximum length of string in java

In java, String can act as a data type and a class. The string can be defined as the collection of characters that are enclosed with double quotes(“ “). The...

3 minutes read.

What is interpreter in Java?

The programming language Java is platform-neutral. Therefore, can use Java on any platform that supports the Java processor. The Piece of software transforms the Java bytecode contained in the class...

5 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.

Java Try-Catch Block

Java Try Block The handling of the exceptions in a block of code is done with the help of java try block. It throws the code that is enclosed in a...

3 minutes read.

Java Math random() Method

The random() method of Math class returns a double value with a positive sign, less than 1 and greater than or equal to 0.0. This method is properly synchronized with...

1 minute read.

Spliterator in Java 8

In this tutorial, we will understand the meaning of spliterator in java 8. It is just like any other iterator available in java used to traverse the elements of either...

4 minutes read.

Math fma () method in java

In java, the Math module constitutes of fma () Method in it. This method can be accessed in two ways which can be differentiated by the parameters which are given...

4 minutes read.

Comparetoignorecase in Java

In Java, the function compareToIgnoreCase ( ) is part of the String class, which is part of the java.lang package. It is used to compare any two strings while disregarding...

4 minutes read.

Java For Loop

A for loop is used to execute a set of statements for a fixed number of times. It takes the following form: for (initialization; condition; update) { statements; } The for loop defines...

2 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.

Java DatagramSocket and Java DatagramPacket

Datagrams TCP/IP style networking specifies a serialized, predictable, and reliable stream of data in the form of a packet. Servers and clients communicate through a reliable channel, such as TCP socket, have a dedicated...

6 minutes read.

Java 9 Interface Private Method

Java 9 provides us the facility to include private methods inside the java interface. In java 8 and earlier versions, we are supposed to use only constant variables and abstract...

3 minutes read.

Java LinkedHashMap

LinkedHashMap implements the Map interface. It inherits the HashMap class. Some essential features of LinkedHashMap are: It contains the values based on the keys. It maintains the order of insertion. It contains unique...

5 minutes read.