Java Math hipot ()

Metoda hipotete Java Math izračuna kvadratni koren x2 + y2 (tj. Hipotenuze) in ga vrne.

Sintaksa hypot()metode je:

 Math.hypot(double x, double y)

Opomba : hypot()Metoda je statična metoda. Zato lahko metodo pokličemo neposredno z imenom razreda Math.

hipot () parametri

  • x, y - dvojni argumenti

hypot () Vrnjene vrednosti

  • vrne Math.sqrt (x 2 + y 2 )

Vrnjena vrednost mora biti znotraj obsega doublepodatkovnega tipa.

Opomba : Math.sqrt()Metoda vrne kvadratni koren določenih argumentov. Če želite izvedeti več, obiščite Java Math.sqrt ().

Primer 1: Java Math.hypot ()

 class Main ( public static void main(String() args) ( // create variables double x = 4.0; double y = 3.0; //compute Math.hypot() System.out.println(Math.hypot(x, y)); // 5.0 ) )

Primer 2: Pitagorin izrek z uporabo Math.hypot ()

 class Main ( public static void main(String() args) ( // sides of triangle double side1 = 6.0; double side2 = 8.0; // According to Pythagoras Theorem // hypotenuse = (side1)2 + (side2)2 double hypotenuse1 = (side1) *(side1) + (side2) * (side2); System.out.println(Math.sqrt(hypotenuse1)); // prints 10.0 // Compute Hypotenuse using Math.hypot() // Math.hypot() gives √((side1)2 + (side2)2) double hypotenuse2 = Math.hypot(side1, side2); System.out.println(hypotenuse2); // prints 10.0 ) )

V zgornjem primeru smo Math.hypot()za izračun hipotenuze trikotnika uporabili metodo in Pitagorin izrek.

Zanimive Članki...