Java.lang Package Classes

Java Math - hypot() Method



The java.lang.Math.hypot() method returns square root of sum of squares of two arguments, i.e., sqrt(x2 +y2). In special cases it returns the following:

  • If either argument is infinite, then the result is positive infinity.
  • If either argument is NaN and neither argument is infinite, then the result is NaN.

Syntax

public static double hypot(double x, double y)

Parameters

x Specify a value.
y Specify a value.

Return Value

Returns sqrt(x2 +y2).

Exception

NA.

Example:

In the example below, hypot() method returns sqrt(x2 +y2).

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.hypot(3, 4));   
  System.out.println(Math.hypot(5, 12));
  System.out.println(Math.hypot(8, 15));     
 }
}

The output of the above code will be:

5.0
13.0
17.0

❮ Java.lang - Math