Description :

This java tutorial shows how to use the log10(double a) method of Math class under java.lang package. This method returns the base 10 logarithm of a value specified as method argument.

Method Syntax :

public static double log10(double a)

Parameter Input :

DataType Parameter Description
double a the value which we want to determine the base 10 logarithm

Method Returns :

The log10(double a) method simply returns the base 10 logarithm of a in consideration of the following special cases:

• 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.

Compatibility Version :

Requires Java 1.5 and up

N/A

Java Code Example :

This java example source code demonstrates the use of log10(double a) method of Math class. Basically we just ask for user input and then we will get the logarithm base 10.

```package com.javatutorialhq.java.examples;

import static java.lang.System.*;

import java.util.Scanner;

/*
* This example source code demonstrates the use of
* log10(double a) method of Math class
* Get the logarithmic value at base 10 of the user input
*/

public class MathLogarithmBase10 {

public static void main(String[] args) {
out.print("Enter a value:");
Scanner scan = new Scanner(System.in);
// use scanner to get user console input
double value = scan.nextDouble();
// get the logarithm value base 10
double logValue = Math.log10(value);
out.println("logarithm of "+value+" = "+logValue);
// close the scanner object to avoid memory leak
scan.close();

}

}```

Sample Output :

Running the log10(double a) method example source code of Math class will give you the following output

```Enter a value:10
logarithm of 10.0 = 1.0```

N/A

• N/A