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

Syntax:

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.
Examples :

Input: num1 = 3
num2 = 4

Output: 5.0


Below programs illustrate the Java.lang.StrictMath.hypot() Method:
Program 1:

 // Java praogram to illustrate the  // Java.lang.StrictMath.hypot() Method  import java.lang.*;     public class Geeks {         public static void main(String[] args)      {             double num1 = 11, num2 = 13.8;             // It returns the hypotenuse          double hypotlen = StrictMath.hypot(num1, num2);          System.out.println("Length of hypotenuse  of side "         + num1 + " & " + num2 + " = " + hypotlen);      }  }

Output:

Length of hypotenuse  of side 11.0 & 13.8 = 17.647662734764623


Program 2:

 // Java praogram to illustrate the  // Java.lang.StrictMath.hypot() Method  import java.lang.*;     public class Geeks {         public static void main(String[] args)      {             double num1 = -54, num2 = -24.8;             // It returns the hypotenuse          double hypotlen = StrictMath.hypot(num1, num2);          System.out.println("Length of hypotenuse  of side "         + num1 + " & " + num2 + " = " + hypotlen);      }  }

Output:

Length of hypotenuse  of side -54.0 & -24.8 = 59.422554640473


Program 3:

 // Java praogram to illustrate the  // Java.lang.StrictMath.hypot() Method  import java.lang.*;     public class Geeks {         public static void main(String[] args)      {             double num1 = 4;          double positive_Infinity = Double.POSITIVE_INFINITY;          double negative_Infinity = Double.NEGATIVE_INFINITY;          double nan = Double.NaN;             // When 1 or more argument is NAN          double hypotlen = StrictMath.hypot(nan, num1);          System.out.println("Hypotenuse length = " + hypotlen);             // When both arguments are infinity          hypotlen = StrictMath.hypot(positive_Infinity,                                      negative_Infinity);          System.out.println("Hypotenuse length = " + hypotlen);      }  }

Output:

Hypotenuse length = NaN
Hypotenuse length = Infinity


My Personal Notes arrow_drop_up lets make it a lil simple

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : Shivam_k

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6286413,"math_prob":0.8375985,"size":3830,"snap":"2019-51-2020-05","text_gpt3_token_len":1024,"char_repetition_ratio":0.18478829,"word_repetition_ratio":0.25123152,"special_character_ratio":0.26344648,"punctuation_ratio":0.16371681,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9961671,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,4,null,8,null,8,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-22T14:26:19Z\",\"WARC-Record-ID\":\"<urn:uuid:c574858c-5e7f-4b46-a66e-a1f1ce4f51f2>\",\"Content-Length\":\"140487\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:063ccaeb-8639-4026-bf4e-930531f35c4a>\",\"WARC-Concurrent-To\":\"<urn:uuid:1bdd9c5b-05c5-4853-8e86-163fb735ba5f>\",\"WARC-IP-Address\":\"23.199.63.179\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/strictmath-hypot-method-in-java/\",\"WARC-Payload-Digest\":\"sha1:WJUPXVIEXCIKCL3HULTK2WWWTKJKE4PM\",\"WARC-Block-Digest\":\"sha1:Y3FVCFNRV3SPZFRHQZYIR5QABBEQIVQN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250607118.51_warc_CC-MAIN-20200122131612-20200122160612-00327.warc.gz\"}"}