# Java log10 Function

Java log10 is a Math Library function that returns a given number’s base 10 logarithmic value. The syntax of Math.log10 in Java accepts positive double values & returns the base 10 logarithmic value.

```static double log10(double number); //Return Type is Double

// To use in program:
Math.log10(double number);```

## Java log10 Function Example

In this Java Math program, we are going to find log10 values for different data.

```package MathFunctions;

public class Log10Method {
public static void main(String[] args) {
double a = Math.log10(100.90 + 150.10 - 220.50 + 10.50);
System.out.println("Logarithmic Value = " + a);

System.out.println("\nLogarithmic Value of Zero: " + Math.log10(0));

System.out.println("\nLogarithmic Value of Positive Number: " + Math.log10(1));
System.out.println("Logarithmic Value of Positive Number: " + Math.log10(10.95));

System.out.println("\nLogarithmic Value of Negative Number: " + Math.log10(-8.70));
System.out.println("Logarithmic Value of Negative Number: " + Math.log10(-5.00));
}
}```

First, We declared a variable of type Double and performed the Math.log10 function directly on the expression.

```double a = Math.log10(100.90 + 150.10 - 220.50 + 10.50);
System.out.println("Logarithmic Value = " + a);```

Next, We used the Math function directly on Positive double values.

```System.out.println("\nLogarithmic Value of Positive Number: " + Math.log10(1));
System.out.println("Logarithmic Value of Positive Number: " + Math.log10(10.95));```

Next, We used the Math.log10 Function directly on Negative double values. As you can see from the screenshot, it is returning NaN for negative values.

```System.out.println("\nLogarithmic Value of Negative Number: " + Math.log10(-8.70));
System.out.println("Logarithmic Value of Negative Number: " + Math.log10(-5.00));```

## Java log10 on Array example

In this Java program, we show how to find the base 10 logarithmic value of bulk data. Here, we are going to declare an Array of double type and find the base 10 logarithmic value of every element in an array.

```package MathFunctions;

public class Log10MethodOnArrays {
public static void main(String[] args) {

double [] logArray = {20.35, 54.98, -68.41, -9.5987, -0, 120.38, 14.4897};

for (int i = 0; i < logArray.length; i++) {
System.out.format("Logarithmic Value of Array Element = %.4f\n", Math.log10(logArray[i]));
}
}
}```
``````Logarithmic Value of Array Element = 1.3086
Logarithmic Value of Array Element = 1.7402
Logarithmic Value of Array Element = NaN
Logarithmic Value of Array Element = NaN
Logarithmic Value of Array Element = -Infinity
Logarithmic Value of Array Element = 2.0806
Logarithmic Value of Array Element = 1.1611``````

Within this log10 function example, First, We declared an Array of double types and assigned some random values.

`double [] logArray = {20.35, 54.98, -68.41, -9.5987, -0, 120.38, 14.4897};`

Next, We used Java For Loop to iterate the Array. Within the For Loop, we initialized the i value as 0. Next, the compiler will check for the condition (i < logArray.length). As along the loop, the condition is True, the statement inside the for loop is executed.

TIP: logArray.length is to find the length of an array.

`for (int i = 0; i < logArray.length; i++) {`

The following Java statements will print the output. If you observe the code snippet, we used the log10 Function directly inside the System.out.format statement. Here, the Jcompiler will call the static double log10(double number) method to find the base 10 logarithmic value of corresponding values.

`System.out.format("Logarithmic Value of Array Element = %.4f\n", Math.log10(logArray[i]));`

NOTE: If you want to find the base 10 logarithmic value of a single item, then use: Math.log10(myArray[index_position])

## Java log10 function on Arraylist example

In this program, we are going to declare an ArrayList of double type and find the base 10 logarithmic value of list elements.

Within this example, First, We declared an ArrayList of double type and assigned some random values.

Next, We used the For Loop to iterate the double values in ArrayList

The System.out.println statements will print the output. Here, the Jcompiler will call the static double log10(double x) method to find the base 10 logarithmic value of corresponding values.

```package MathFunctions;

import java.util.ArrayList;

public class Log10MethodOnArrayList {
public static void main(String[] args) {

ArrayList<Double> logList = new ArrayList<Double>(5);
``````3.0955173452206943