log10()
方法的语法是
Math.log10(double x)
这里,log10()
是一个静态方法。因此,我们直接使用类名 Math
来调用该方法。
log10() 参数
- x - 要计算对数的数值
log10() 返回值
- 返回 x 的以 10 为底的对数
- 如果 x 是 NaN 或小于零,则返回 NaN
- 如果 x 是正无穷大,则返回正无穷大
- 如果 x 是零,则返回负无穷大
注意:log10(10n) = n
,其中 n 是一个 整数。
示例:Java Math.log10()
class Main {
public static void main(String[] args) {
// compute log10() for double value
System.out.println(Math.log10(9.0)); // 0.9542425094393249
// compute log10() for zero
System.out.println(Math.log10(0.0)); // -Infinity
// compute log10() for NaN
double nanValue = Math.sqrt(-5.0);
System.out.println(Math.log10(nanValue)); // NaN
// compute log10() for infinity
double infinity = Double.POSITIVE_INFINITY;
System.out.println(Math.log10(infinity)); // Infinity
// compute log10() for negative numbers
System.out.println(Math.log(-9.0)); // NaN
//compute log10() for 103
System.out.println(Math.log10(Math.pow(10, 3))); // 3.0
}
}
在上面的示例中,请注意表达式,
Math.log10(Math.pow(10, 3))
这里,Math.pow(10, 3)
返回 103。要了解更多,请访问 Java Math.pow()。
另请阅读