A Java Math hypot () módszer kiszámítja az x2 + y2 (azaz a hipotenusz) négyzetgyökét és visszaadja azt.
A hypot()
módszer szintaxisa :
Math.hypot(double x, double y)
Megjegyzés : A hypot()
módszer statikus módszer. Ezért a metódust közvetlenül az osztály nevével hívhatjuk meg Math
.
hipot () Paraméterek
- x, y - kettős típusú argumentumok
hipot () Visszatérési értékek
- a Math.sqrt (x 2 + y 2 ) eredményt adja
A visszaadott értéknek az double
adattípus tartományán belül kell lennie .
Megjegyzés : A Math.sqrt()
módszer a megadott argumentumok négyzetgyökét adja vissza. További információkért látogasson el a Java Math.sqrt () oldalra.
1. példa: 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 ) )
2. példa: Pythagoras-tétel a Math.hypot () használatával
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 ) )
A fenti példában a Math.hypot()
módszert és a Pitagorasz-tételt használtuk egy háromszög hipotenuszának kiszámításához.