Java log10() 及示例
java.lang.Math.log10(double a) 返回双精度值的以 10 为底的对数。特殊情况 -
如果参数为 NaN 或小于零,则结果为 NaN。
如果参数为正无穷大,则结果为正无穷大。
如果参数为正零或负零,则结果为负无穷大。
如果参数等于整数 n 的 10^n,则结果为 n。
示例
以下是一个在 Java 中实现 log10() 方法的示例 -
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
double x = 56567.5;
double y = 100;
// get the base 10 logarithm for x
System.out.println("Math.log10(" + x + ")=" + Math.log10(x));
// get the base 10 logarithm for y
System.out.println("Math.log10(" + y + ")=" + Math.log10(y));
}
}输出
Math.log10(56567.5)=4.752566985524987 Math.log10(100.0)=2.0
让我们看另一个示例 -
示例
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
double x = -30;
double y = 1.0 / 0; ;
// get the base 10 logarithm for x
System.out.println("Math.log10(" + x + ")=" + Math.log10(x));
// get the base 10 logarithm for y
System.out.println("Math.log10(" + y + ")=" + Math.log10(y));
}
}输出
Math.log10(-30.0)=NaN Math.log10(Infinity)=Infinity
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP