English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel de base Java

Java Contrôle de flux

Java Tableau

Java Orienté Objet (I)

Java Orienté Objet (II)

Java Orienté Objet (III)

Gestion des exceptions Java

Java List

Java Queue (file d'attente)

Java Map Collection

Java Set Collection

Java Entrée/Sortie (I/O)

Java Reader/Writer

Autres sujets Java

Méthode et exemple d'utilisation de Java Math hypot()

Java Math mathematical methods

Java Math hypot() méthode calcule x2 + y2La racine carrée (c'est-à-dire, le côté opposé) de l'argument spécifié et le renvoie.

La syntaxe de la méthode hypot() est :

Math.hypot(double x, double y)

Remarque:La méthode hypot() est une méthode statique. Par conséquent, nous pouvons appeler cette méthode directement en utilisant le nom de la classe Math.

Paramètres de hypot()

  • x,y - Paramètres de type double

La valeur retournée par hypot()

  • ReturnMath.sqrt(x 2 + y 2

La valeur retournée doit être dans la plage de types de données double.

Remarque:La méthode Math.sqrt() renvoie la racine carrée de l'argument spécifié. Pour plus d'informations, veuillez visiterJava Math.sqrt()

Example1:Java Math.hypot()

class Main {
  public static void main(String[] args) {
    //Créer une variable
    double x =; 4.0;
    double y =; 3.0;
    //Calculer Math.hypot()
    System.out.println(Math.hypot(x, y));  // 5.0
  }
}

Example2:Using the Pythagorean theorem with Math.hypot()

class Main {
  public static void main(String[] args) {
    //The sides of a triangle
    double  side1 = 6.0;
    double side2 = 8.0;
    //According to the Pythagorean theorem
    // hypotenuse = (side1)2 + (side2)2
    double hypotenuse1 = (side1) *(side1) + (side2) * (side2);
    System.out.println(Math.sqrt(hypotenuse1);    // Return 10.0
    // The hypotenuse calculation uses Math.hypot()
    // Math.hypot() gives √((side1)2 + (side2)2)
    double hypotenuse2 = Math.hypot(side1, side2);
    System.out.println(hypotenuse2);               // Return 10.0
  }
}

In the above example, we use the Math.hypot() method and the Pythagorean theorem to calculate the hypotenuse of a triangle.

Java Math mathematical methods