English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math hypot() 메서드는 x2 + y2의 제곱근(즉, 직각三角의 hypotenuse)을 반환합니다。
hypot() 메서드의 문법은 다음과 같습니다:
Math.hypot(double x, double y)
주의:hypot() 메서드는 정적 메서드입니다. 따라서 Math 클래스 이름을 사용하여 이 메서드를 호출할 수 있습니다。
x, y - double 타입 파라미터
返回Math.sqrt(x 2 + y 2)
반환된 값은 double 데이터 타입의 범위 내에 있어야 합니다。
주의:Math.sqrt() 메서드는 지정된 매개변수의 제곱근을 반환합니다. 더 많은 정보를 얻으려면 방문하세요Java Math.sqrt()。
class Main { public static void main(String[] args) { //创建变量 double x =; 4.0; double y =; 3.0; //计算 Math.hypot() System.out.println(Math.hypot(x, y)); // 5.0 } }
class Main { public static void main(String[] args) { //삼각형의 변 double side1 = 6.0; double side2 = 8.0; //피타고라스 정리에 따라 // hypotenuse = (side1)2 + (side2)2 double hypotenuse1 = (side1) *(side1) + (side2) * (side2); System.out.println(Math.sqrt(hypotenuse1)); // 返回 10.0 // 대각선 계산에 사용되는 Math.hypot() // Math.hypot() gives √((side1)2 + (side2)2) double hypotenuse2 = Math.hypot(side1, side2); System.out.println(hypotenuse2); // 返回 10.0 } }
위의 예제에서 우리는 Math.hypot() 메서드와 피타고라스 정리를 사용하여 삼각형의 대각선을 계산했습니다.