Java .log10()
Published Oct 31, 2022Updated Nov 12, 2022
Contribute to Docs
The Math.log10() method returns the base-10 logarithm of a number.
Syntax
Math.log10(a);
- If
ais a positive number, the return value is adouble. - If
aisNaNor a negative number, the return value isNaN. - If
ais positive infinity, the return value is positive infinity. - If
ais negative or positive zero, the return value is negative infinity. - If
ais 10n for integern, the return value isn.
Example
The following example demonstrates using the .log10() method to find base-10 logarithms:
// Main.javapublic class Main {public static void main(String args[]) {double a = 10;double b = -6;double c = 0;double d = -0;System.out.println("The result of log10(" + a + ") is: " + Math.log10(a));System.out.println("The result of log10(" + b + ") is: " + Math.log10(b));System.out.println("The result of log10(" + c + ") is: " + Math.log10(c));System.out.println("The result of log10(" + d + ") is: " + Math.log10(d));}}
This will produce the following output:
The result of log10(10.0) is: 1The result of log10(-6.0) is: NaNThe result of log10(0.0) is: -InfinityThe result of log10(0.0) is: -Infinity
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
- Beginner Friendly.17 hours