Java cbrt() 方法附带示例
java.lang.Math.cbrt(double a) 返回 double 值的立方根。对于正无穷大 x,cbrt(-x) == -cbrt(x);也就是说,负数值的立方根是该值的绝对值的立方根的相反数。特殊情况 -
如果参数为 NaN,则结果为 NaN。
如果参数为无穷大,则结果为无穷大,符号与参数相同。
如果参数为零,则结果为零,符号与参数相同。
示例
以下是 Java 中实现 cbrt() 方法的一个示例 -
import java.lang.*;
public class Example {
public static void main(String[] args) {
// get two double numbers
double x = 125;
double y = 10;
// print the cube roots of three numbers
System.out.println("Math.cbrt(" + x + ")=" + Math.cbrt(x));
System.out.println("Math.cbrt(" + y + ")=" + Math.cbrt(y));
System.out.println("Math.cbrt(-27)=" + Math.cbrt(-27));
}
}输出
Math.cbrt(125.0)=5.0 Math.cbrt(10.0)=2.154434690031884 Math.cbrt(-27)=-3.0
示例
我们看另一个示例 -
import java.lang.*;
public class Example {
public static void main(String[] args) {
// get two double numbers
double x = 0.0;
double y = -343.0;
// print the cube roots of three numbers
System.out.println("Math.cbrt(" + x + ")=" + Math.cbrt(x));
System.out.println("Math.cbrt(" + y + ")=" + Math.cbrt(y));
}
}输出
Math.cbrt(0.0)=0.0 Math.cbrt(-343.0)=-7.0
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP