English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
Java Math sqrt() يرجع الجذر التربيعي للرقم المحدد.
نظام اللغة Java Math sqrt()
Math.sqrt(double num)
ملاحظة:sqrt() هي طريقة ثابتة. لذلك، يمكننا استخدام اسم الكائن لاستدعاء هذه الطريقة.
num -رقم يجب حساب جذر تربيعه
إرجاع الجذر التربيعي للرقم المحدد
إذا كان المعامل أقل من الصفر أو NaN، فإنه يعود NaN
ملاحظة:يستخدم هذا الطريقة دائمًا الرقم الإيجابي ويشير إلى التقريب.
class Main { public static void main(String[] args) { //إنشاء متغير ذو دقة عالية double value1 = Double.POSITIVE_INFINITY; double value2 = 25.0; double value3 = -16; double value4 = 0.0; //الجذر التربيعي للعدد الكبير System.out.println(Math.sqrt(value1)); // Infinity // Square root of a positive number System.out.println(Math.sqrt(value2)); // 5.0 // Square root of a negative number System.out.println(Math.sqrt(value3)); // NaN // Square root of zero System.out.println(Math.sqrt(value4)); // 0.0 } }
In the above example, we used the Math.sqrt() method to calculate the square root of infinity, positive numbers, negative numbers, and zero.
Here, Double.POSITIVE_INFINITY is used to implement positive infinity in the program.
When we pass an int value to the sqrt() method, it automatically converts the int value to a double value.
int a = 36; Math.sqrt(a); // Returns 6.0