„Java Math hypot“ () metodas apskaičiuoja kvadratinę x2 + y2 šaknį (ty hipotenuzą) ir grąžina ją.
hypot()
Metodo sintaksė yra tokia:
Math.hypot(double x, double y)
Pastaba : hypot()
metodas yra statinis. Vadinasi, metodą galime iškviesti tiesiogiai naudodami klasės pavadinimą Math
.
hipot () parametrai
- x, y - dvigubo tipo argumentai
hipot () Grąžinimo vertės
- grąžina Math.sqrt (x 2 + y 2 )
Grąžinta vertė turėtų būti double
duomenų tipo diapazone .
Pastaba : Math.sqrt()
metodas pateikia nurodytų argumentų kvadratinę šaknį. Norėdami sužinoti daugiau, apsilankykite „Java Math.sqrt“ ().
1 pavyzdys: 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 pavyzdys: Pitagoro teorema naudojant 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 ) )
Ankstesniame pavyzdyje mes naudojome Math.hypot()
metodą ir Pitagoro teoremą trikampio hipotenuzei apskaičiuoti.