StrictMath hypot() Method in Java
According to basic geometry, hypotenuse is nothing but the longest side of a right-angled triangle. It is the side which is opposite to the right angle of the triangle. To find the length of the hypotenuse of a right-angled triangle, the Pythagorean theorem is applied. According to this theorem, given two perpendicular sides of a triangle of length p and b, the hypotenuse can be found by the formula .
The Java.lang.StrictMath.hypot() is an inbuilt method of StrictMath class which is used to get the hypotenuse or the square-root of summation of the square of given two sides or arguments i.e. . The method excludes all the intermediate overflow and underflow. It gives rise to few special results:
- The method returns positive infinity when either of num1 or num2 is infinite.
- It returns NAN when either any argument is NAN and neither argument is infinite.
public static double hypot(double num1, double num2)
Parameters: The method accepts two parameters of Double type:
- num1: This is the first value or any one side.
- num2: This is the second value or the other side.
Return Value: The method returns i.e. length of hypotenuse.
Input: num1 = 3 num2 = 4 Output: 5.0
Below programs illustrate the Java.lang.StrictMath.hypot() Method:
Length of hypotenuse of side 11.0 & 13.8 = 17.647662734764623
Length of hypotenuse of side -54.0 & -24.8 = 59.422554640473
Hypotenuse length = NaN Hypotenuse length = Infinity