hypot() in Java

hypot(): This method is available in the Math class of Java.

Syntax:

double java.lang.Math.hypot(double x, double y)

This method takes two parameters of type double. This method returns sqrt(x^2 +y^2) without intermediate overflow or underflow.

Special cases: 

1. If either argument is infinite, then the result is positive infinity.

2. If either argument is NaN and neither argument is infinite, then the result is NaN.

Parameters: Two parameters are required for this method.

x: a value.

y: a value.

Returns:sqrt(x^2 +y^2) without intermediate overflow or underflow.

For Example:

Math.hypot(8,6) = > It returns 10.0

Approach

Java

public class Hypot {
    public static void main(String[] args) {

        double x = 8, y = 6;
        System.out.println(Math.hypot(x, y));

    }
}

Output:

10.0

No comments:

Post a Comment