English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math mathematical methods
Méthode Java Math pow() pour obtenir la puissance (bimes de a).
C'est-à-dire, pow(a, b) = ab
La syntaxe de la méthode pow() est :
Math.pow(double num1, double num2)
Remarque:pow() est une méthode statique. Par conséquent, nous pouvons utiliser le nom de la classe pour accéder à cette méthode Math.
num1 - Paramètres de base
num2 - Paramètre d'exponentiation
Le résultat retourné num1num2
Si num2Si zéro, retourne 1.0
Si num1Si zéro, retourne 0.0
class Main { public static void main(String[] args) { //Création d'une variable double double num1 = 5.0; double num2 = 3.0; // Math.pow() avec un nombre positif System.out.println(Math.pow(num1, num2)); // 125.0 //Math.pow() avec zéro double zero = 0.0; System.out.println(Math.pow(num1, zero)); // 0.0 System.out.println(Math.pow(zero, num2)); // 1.0 //Math.pow() avec l'infini double infinity = Double.POSITIVE_INFINITY; System.out.println(Math.pow(num1, infinity)); // Infinity System.out.println(Math.pow(infinity, num2)); // Infinity //Negative number Math.pow() System.out.println(Math.pow(-num1, -num2)); // 0.008 } }
In the above example, we used Math.pow() withpositive numbers,negative numbers,zeroandInfinite.
Here, Double.POSITIVE_INFINITY is used to implement positive infinity in the program.
When we pass an int value to the pow() method, it automatically converts the int value to the double value.
int a = 2; int b = 5; Math.pow(a, b); // Return 32.0