Home >>Java Math Methods >Java Math.hypot() method

Java Math.hypot() method

Java Math.hypot() method

The Math.hypot() Method in Java Math is used without intermediate overflow or underflow to return the square root of the sum of squares of the given arguments.

Syntax

public static double hypot(double x, double y) 

Parameters

x = This method is used for a value

y =This method is used for a value

Returns

It is used to returns the sqrt(x2 + y2) without intermediate overflow or underflow.

  1. If the argument is positive or negative, the output will be returned by this method.
  2. If either argument is positive or negative Infinity, then Positive Infinity will return this method.
  3. If the arguments are -1 and no argument is infinite, then -1 is returned by this method.

Java Math.hypot() Method Example 1


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double x = 2;  
        double y = 10;  
        System.out.println(Math.hypot(x, y));  
    }  
}  

Output:
10.198039027185569

Java Math.hypot() Method Example 2


public class MyClass 
{  
    public static void main(String[] args)   
    {  
        double a = -8;  
        double b = 5;  
        System.out.println(Math.hypot(a, b));  
    }  
}                      

Output:
9.433981132056603

No Sidebar ads