×

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

Adapter class in Java

By using the adapter classes, we can implement Listener interfaces. With the help of adapter classes, we can save code as it provides all implementation methods of listener interfaces Advantages of...

3 minutes read.

Java Code Coverage Tools

Code coverage testing is a crucial metric that gauges how thoroughly the program's source code has been tested. The market is flooded with Code Coverage Tools, making it difficult to...

7 minutes read.

Java Read File to String

There are different ways to deal with forming and examining a text record. This is normal while dealing with various applications. There are different ways to deal with looking at a...

6 minutes read.

Java Map Interface

A map is a collection that maps keys to values, with no duplicate keys allowed. The elements in a map are key/value pairs. HashMap: HashMap stores the keys in a...

3 minutes read.

Dining Philosophers problem in Java

The Problem of the Dining Philosophers illustrates a concurrency issue involving the distribution of scarce resources among conflicting processes. Problem Statement Imagine a dining table with a circle in the middle and five...

3 minutes read.

Arithmetic Operations on String in Java

Introduction Arithmetic, Relational, Bitwise, and Logical operators are all available in Java. Simple mathematical calculations are performed using Java arithmetic operators. Basic Arithmetic operators are considered in Java to be Addition,...

4 minutes read.

Java Thread class

Thread class The thread represents a part of the process. Every process can have multiple associated threads in which every thread may execute the same or different job. By default, each thread assigns...

16 minutes read.

Java Transient Keyword

An object in Java can be turned into a stream of bytes using serialization. The data of the instance and the kind of data saved in that instance are both...

3 minutes read.

Association in Java

In Java, association refers to the link between two classes established by their objects. One-to-one, one-to-many, and many-to-many connections are managed via association. The Association defines the multiplicity between objects...

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

Maximizing Profit in Stock Buy Sell in Java

In this tutorial, we will deal with a popular problem, a favourite of interviewers. The problem is named as Maximising profit in stock Buy Sell. we will see certain approaches...

6 minutes read.

Thread States in Java

An Item's Life Cycle (Thread States) A thread can be in any of the states mentioned above at any given time in Java. They are as follows: New Active I'm blocked or waiting Temporary...

3 minutes read.

Java File Input Stream

Java makes use of stream ideas to speed up input and output processes. All packages of input and output streams are contained in java.io.package. Stream: A stream is nothing more...

5 minutes read.

Shallow copy in Java

Java's most important task is making a copy or clone of an object. In this part, we'll talk about shallow copies in Java and how to make them of Java...

4 minutes read.

Equilibrium Index of an Array in Java

An array's equilibrium index is the condition where the sum of items with lower and higher indices equals. For example, an array A=[-4,5 2,6,-5] where: a[0]=-4, a[1]=5, a[2]=2, a[3]=6, a[4]=-5 Now according...

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

Package Program in Java

Package Program in Java The package program in Java helps us to understand the significance of packages in Java. Packages are mainly used to group together similar classes, interfaces and sub-packages....

6 minutes read.

Java New Keyword

To create a class instance in Java, use the new keyword. In other words, it returns a reference to the memory that was allocated for a new object and instantiates...

3 minutes read.

Recursion Program in Java

The recursion program in Java demonstrates the usage of recursion. The process by which a function/ method calls itself, again and again, is called recursion. Each recursive call is pushed...

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