Calculate hyperbolic tangent in Java
Description
The following code shows how to calculate hyperbolic tangent.
Example
//www . jav a 2 s . c o m
public strictfp class Main {
public static void main(String[] args) {
// Obtain angle in degrees from user
double degs = 20d;
// Convert degrees to radian
double rads = Math.toRadians(degs);
// Calculate hyperbolic sine
double sinHA = (Math.exp(rads) - Math.exp(-rads)) / 2;
System.out.println("Hyperbolic sine = " + sinHA);
// Calculate Hyperbolic cosine
double cosHA = (Math.exp(rads) + Math.exp(-rads)) / 2;
System.out.println("Hyperbolic cosine = " + cosHA);
// Calculate hyperbolic tangent
double tanHA = sinHA / cosHA;
System.out.println("Hyperbolic tangent = " + tanHA);
}
}