Hypot is a mathematical function defined to calculate the length of the hypotenuse of a right-angle triangle. It was designed to avoid errors arising due to limited-precision calculations performed on computers.

From: Wikipedia

The `Math.hypot(double x, double y)`

return the `sqrt(x`

^{2}`+ y`

^{2}`)`

without intermediate overflow or underflow. The result will be same with this calculation

`Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))`

.

```
package org.kodejava.example.math;
public class HypotExample {
public static void main(String[] args) {
double number1 = 3.0d;
double number2 = 5.0d;
// calculate square root of total value of
// number1 ^ 2 + number2 ^ 2
double sqr = Math.hypot(number1, number2);
System.out.println("Total value = " + (Math.pow(number1, 2) + Math.pow(number2, 2)));
System.out.println("Square root = " + sqr);
}
}
```

### Wayan Saryada

Founder at Kode Java Org

I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you đź™‚.

#### Latest posts by Wayan Saryada (see all)

- How do I write JSON string using JSON-Java (org.json) library? - August 31, 2018
- How do I read JSON file using JSON-Java (org.json) library? - August 31, 2018
- Install IntelliJ IDEA Community Edition and Write Hello Kotlin Program - May 13, 2018