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