Java.lang Package Classes

Java Math - log10() Method



The java.lang.Math.log10() method returns the base-10 logarithm of a given number. In special cases it returns the following:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is negative infinity.
  • If the argument is equal to 10n for integer n, then the result is n.

Syntax

public static double log10(double a)

Parameters

a Specify the number.

Return Value

Returns the base-10 logarithm of a given number.

Exception

NA.

Example:

In the example below, log10() method is used to calculate the base-10 logarithm of a given number.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.log10(10)); 
  System.out.println(Math.log10(50)); 
  System.out.println(Math.log10(100));     
 }
}

The output of the above code will be:

1.0
1.6989700043360187
2.0

❮ Java.lang - Math