English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
O método cbrt() da Java Math retorna a raiz cúbica do número especificado.
A sintaxe do método cbrt() é:
Math.cbrt(double num)
Atenção:cbrt() é um método estático. Portanto,podemos usar o nome da classe para acessar o método Math.
num - O número a calcular a raiz cúbica
Retorna a raiz cúbica do número especificado
Se o valor especificado for NaN,retorna NaN
Se o número especificado for 0,retorna 0
Atenção:se o parâmetro for um número negativo-num,então cbrt(-num) = -cbrt(num).
class Main { public static void main(String[] args) { // Create a double variable double value1 = Double.POSITIVE_INFINITY; double value2 = 27.0; double value3 = -64; double value4 = 0.0; // Infinity's cubic root System.out.println(Math.cbrt(value1)); // Infinity // Positive number's cubic root System.out.println(Math.cbrt(value2)); // 3.0 // Negative number's cubic root System.out.println(Math.cbrt(value3)); // -4.0 // Zero's cubic root System.out.println(Math.cbrt(value4)); // 0.0 } }
In the above example, we used the Math.cbrt() method to calculateInfinity,Positive numbers,Negative numbersAndZerocubic root.
Here, Double.POSITIVE_INFINITY is used to implement positive infinity in the program.
When we pass an int value to the cbrt() method, it automatically converts the int value to the double value.
int a = 125; Math.cbrt(a); // Return 5.0