Java Matematik hipotu ()

Java Math hypot () yöntemi, x2 + y2'nin (yani hipotenüs) karekökünü hesaplar ve döndürür.

hypot()Yöntemin sözdizimi şöyledir:

 Math.hypot(double x, double y)

Not : hypot()Yöntem statik bir yöntemdir. Dolayısıyla, yöntemi doğrudan sınıf adını kullanarak çağırabiliriz Math.

hypot () Parametreler

  • x, y - çift tip argümanlar

hypot () Dönüş Değerleri

  • Math.sqrt (x 2 + y 2 ) döndürür

Döndürülen değer, doubleveri türünün aralığı içinde olmalıdır .

Not : Math.sqrt()Yöntem, belirtilen bağımsız değişkenlerin karekökünü döndürür. Daha fazla bilgi edinmek için Java Math.sqrt () adresini ziyaret edin.

Örnek 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 ) )

Örnek 2: Math.hypot () Kullanarak Pisagor Teoremi

 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 ) )

Yukarıdaki örnekte, Math.hypot()bir üçgenin hipotenüsünü hesaplamak için yöntemi ve Pisagor Teoremini kullandık.

Ilginç makaleler...