Home » Java programming language

Java Math Class static double cosh(double d) with example

Java Math Class double cosh(double d) method: Here, we are going to learn about the double cosh(double d) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 02, 2019

Math Class double cosh(double d)

  • This method is available in java.lang package.
  • In this method, cosh stands for hyperbolic cosine of an angle.
  • This method is used to return the hyperbolic cosine of an angle of the given parameter.
  • This is a static method so it is accessible with the class name too.
  • The return type of this method is double that means it returns the hyperbolic cosine value of the given argument.
  • In this method, we pass only one double type parameter as an argument (in radians) whose hyperbolic cosine is to be returned.
  • This method does not throw any exception.

Syntax:

    public static double cosh(double d){
    }

Parameter(s): double type parameter as an argument (in radians) whose hyperbolic cosine is to be returned.

Return value:

The return type of this method is double, it returns the hyperbolic cosine of an angle.

Note:

  • If we pass "NaN", it returns "NaN".
  • If we pass an infinity with any sign (positive or negative), it returns the same value.
  • If we pass zero (-0 or 0), it returns 1.0.

Java program to demonstrate example of cosh(double d) method

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

class CoshMethod {
    public static void main(String[] args) {
        // Here we are declaring few variables
        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(" Before implementing cosh() so the value of d1 is : " + d1);
        System.out.println(" Before implementing cosh() so the value of d2 is : " + d2);
        System.out.println(" Before implementing cosh() so the value of d3 is : " + d3);
        System.out.println(" Before implementing cosh() so the value of d4 is : " + d4);
        System.out.println(" Before implementing cosh() so the value of d5 is : " + d5);

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

        // Here , we will get (infinity) because we are 
        // passing parameter whose value is (infinity)
        System.out.println("After implementing cos() so the value of d1 is : " + Math.cosh(d1));

        // Here , we will get (infinity) because we are 
        // passing parameter whose value is (-infinity)
        System.out.println("After implementing cosh() so the value of d2 is : " + Math.cosh(d2));

        // Here , we will get (1.0) because we are passing parameter
        // whose value is (0.0)
        System.out.println("After implementing cosh() so the value of d3 is : " + Math.cosh(d3));

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

        // Here we will find hyperbolic cosine of d5 by using cosh() method
        System.out.println("After implementing cosh() so the value of d5 is : " + Math.cosh(d5));
    }
}

Output

E:\Programs>javac CoshMethod.java

E:\Programs>java CoshMethod

Before implementing cosh() so the value of d1 is : Infinity
Before implementing cosh() so the value of d2 is : -Infinity
Before implementing cosh() so the value of d3 is : 0.0
Before implementing cosh() so the value of d4 is : -0.0
Before implementing cosh() so the value of d5 is : 60.0
After implementing cos() so the value of d1 is : Infinity
After implementing cosh() so the value of d2 is : Infinity
After implementing cosh() so the value of d3 is : 1.0
After implementing cosh() so the value of d4 is : 1.0
After implementing cosh() so the value of d5 is : 1.600286857702386



Comments and Discussions!

Load comments ↻






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