Home » Java programming language

Java StrictMath cosh() Method with Example

StrictMath Class cosh() method: Here, we are going to learn about the cosh() method of StrictMath Class with its syntax and example.
Submitted by Preeti Jain, on December 27, 2019

StrictMath Class cosh() method

  • cosh() method is available in java.lang package.
  • cosh() method is used to return the hyperbolic cosine of an angle of the given parameter in the method. Here, "cosh" stands for hyperbolic cosine of an angle.
  • cosh() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • In this method, we pass only radians type argument (i.e. First we convert given argument in radians by using toRadians() method of StrictMath class then after we will pass the same variable in cosh() method).
  • cosh() method does not throw any exception.

Syntax:

    public static double cosh(double d);

Parameter(s):

  • double d – represents the value whose hyperbolic cosine of an angle is to be returned.

Return value:

The return type of this method is double – it returns the hyperbolic cosine value of the given argument.

Note:

  • If we pass NaN, the method returns NaN.
  • If we pass an infinity (positive or negative), the method returns the same value.
  • If we pass a zero (positive or negative), the method returns the 1.0.

Example:

// Java program to demonstrate the example
// of  cosh(double d) method of StrictMath Class.

public class Cosh {
    public static void main(String[] args) {
        // variable declarations
        double d1 = 7.0 / 0.0;
        double d2 = -7.0 / 0.0;
        double d3 = 0.0;
        double d4 = -0.0;
        double d5 = 60.0;

        // Display previous value of d1,d2,d3,d4 and d5
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);
        System.out.println("d5: " + d5);

        // By using toRadians() method to convert 
        // absolute value into radians.
        d1 = StrictMath.toRadians(d1);
        d2 = StrictMath.toRadians(d2);
        d3 = StrictMath.toRadians(d3);
        d4 = StrictMath.toRadians(d4);
        d5 = StrictMath.toRadians(d5);

        // Here , we will get (infinity) because we are 
        // passing parameter whose value is (infinity)
        System.out.println("StrictMath.cosh(d1): " + StrictMath.cosh(d1));

        // Here , we will get (infinity) because we are
        // passing parameter whose value is (-infinity)
        System.out.println("StrictMath.cosh(d2): " + StrictMath.cosh(d2));

        // Here , we will get (1.0) because we are 
        // passing parameter whose value is (0.0)
        System.out.println("StrictMath.cosh(d3): " + StrictMath.cosh(d3));

        // Here , we will get (1.0) because we are 
        // passing parameter whose value is (-0.0)
        System.out.println("StrictMath.cosh(d4): " + StrictMath.cosh(d4));

        // Here we will find hyperbolic cosine of d5 by 
        // using cosh() method
        System.out.println("StrictMath.cosh(d5): " + StrictMath.cosh(d5));
    }
}

Output

d1: Infinity
d2: -Infinity
d3: 0.0
d4: -0.0
d5: 60.0
StrictMath.cosh(d1): Infinity
StrictMath.cosh(d2): Infinity
StrictMath.cosh(d3): 1.0
StrictMath.cosh(d4): 1.0
StrictMath.cosh(d5): 1.600286857702386



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.