English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial Básico de Java

Controle de fluxo do Java

Array do Java

Java orientado a objetos (I)

Java orientado a objetos (II)

Java orientado a objetos (III)

Tratamento de Exceção do Java

Lista do Java (List)

Java Queue (fila)

Conjunto Map do Java

Conjunto Set do Java

Entrada e saída do Java (I/O)

Reader do Java/Writer

Outros tópicos do Java

Uso e exemplo do Java Math cbrt()

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.

Parâmetro cbrt()

  • num - O número a calcular a raiz cúbica

Retorno do valor de cbrt()

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

Exemplo: Java Math cbrt()

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

Related Tutorials

Java Math Mathematical Methods