The Math.hypot() method returns the hypotenuse of a right-angled triangle. The hypotenuse is the square root of x2 + y2, where x and y (of type double) are the sides that form the right angle. It does not return intermediate overflow or underflow, which means the .hypot() method will not fail due to overflow or underflow of a x2 or y2 value.


Math.hypot(x, y)
  • The return type for .hypot() is double.
  • If either the x or y parameter is infinite, the result is positive infinity.
  • If neither argument is infinite, but one or both parameters are NaN, the result is NaN.


The following example demonstrates using .hypot() to find the hypotenuse of a right-angled triangle:

// Test.java
public class Test {
public static void main(String args[]) {
double base_x = 8;
double height_y = 10;
System.out.println(Math.hypot(base_x, height_y));

This results in the following output:



Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Java on Codecademy