×

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

Java Technologies List

Introducing Java technology is not necessary. Everyone across the globe is still in awe of Java's incredible capabilities for developing mobile apps and websites. Of course, you can be persuaded...

8 minutes read.

Sort Elements by Frequency in Java

To sort the elements in Java by using frequency, we need an input array. We should create a function that sorts the elements in an array by using their frequencies...

3 minutes read.

Bad Operand types for Binary Operator Java

We will discuss how to handle issues in bad operand types for binary operator &, bad operand types for binary operator &&, bad operand types for binary operator ==, and...

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

Java Identifiers

In Java, the symbolic notations used for identification are called identifiers. Identifiers can be the name for the class, variable name declaration, name of the package, constant name and many...

3 minutes read.

Read the XLSX file in Java

Excel files contain cells; reading an excel file in Java differs from reading a word file. JDK doesn't have a direct API that can read or write Word or Excel...

3 minutes read.

Java Arrays

An array is an object that stores a collection of values. An array can store two types of collection data: objects and primitives. An array is a collection of values which...

2 minutes read.

Counting sort in Java

An array's elements are sorted using the counting sort method, which counts how many times each distinct element appears in the array. The count is kept in an auxiliary array,...

3 minutes read.

How to Convert String to long in Java

How to Convert String to long in java It is used when you want to perform the mathematical operation on the String which contains long number then the conversion from String...

4 minutes read.

Sorting Program in Java

Sorting Program in Java: The sorting program in Java is used to sort arrays either in ascending or descending order.  There are two predefined methods available in Java that are...

6 minutes read.

Java Instanceof Keyword

To determine whether an object is an instance of the supplied type in Java, use the instanceof operator (class or subclass or interface). The type of comparison in java differentiates the...

4 minutes read.

Time Class Operation in Java

The Java SQL package includes the time class. This class is merely a lightweight wrapper for java. util. THANKS TO THE recognize BC API can recognize this as a SQL...

3 minutes read.

Java 9 Try With Resources

Java 9 provides the improvement in the try statement. It allows us to declare a try statement with duly declared resources. Whenever the user does not require the functionality with...

3 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 If Keyword

Definition: The if statement specifies a section of Java code that will run if an if statement's condition is false. The following conditional statements can be used in Java: To provide a block...

3 minutes read.

Block Swap Algorithm for array rotation in Java

An array and r, the rotation factor by which the array must be rotated, are both provided to us. We must then return the rotated array. A well-known and popular method is...

4 minutes read.

Java List Node

In Java, List Node is the same as the single linked list, which is the collection of nodes. So, we can say, the list nodes are grouped together to get...

8 minutes read.

Creating API Document Javadoc tool

The JavaDoc utility is a document generator tool written in Java that generates standard documentation in HTML format. It parses declarations and documentation in a source file collection that describes...

3 minutes read.

String Programs in Java

String Programs in Java: In Java, a String is an immutable object that represents a sequence of characters. For example, “Tutorial” is a string that consists of 8 characters: ‘T’,...

10 minutes read.

Java Math atan2() Method

The atan2() method of Math class returns an angle theta from the conversion of rectangular coordinates to polar coordinates. Syntax: public static double atan2(double y, double x) Parameters: The parameter ‘y’ represents the ordinate...

3 minutes read.