Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

hypot()

Example

Find the distance between 2D coordinates (x, y) and the origin (0, 0).

System.out.println(Math.hypot(3, 4));
System.out.println(Math.hypot(1, 1));
System.out.println(Math.hypot(1, 10));

Definition and Usage

The hypot() method computes the length of the hypotenuse of a right triangle, representing the distance between a 2D point (x, y) and the origin (0, 0).

It’s essentially equivalent to Math.sqrt(x * x + y * y), but it’s optimized to avoid potential overflows and underflows that may occur during intermediate calculations like addition and multiplication.

Syntax

public static double hypot(double x, double y)

Parameter Values

Parameter

Description

x

Mandatory. The x-coordinate of a point.

y

Necessary. The y-coordinate of a point.

Technical Details

Return

A double value indicating the distance from a point (x, y) to the origin (0, 0).

Java Version

1.5+