Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

Java log10 Function

Java log10 is a Math Library function, used to return the base 10 logarithmic value of a given number. The syntax of Math.log10 in Java accepts positive double value & 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.log10 program, we are going to find log10 values for different data.

// Java Math.log10 Function
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)); 
 }
}
Java log10 Function 1

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

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

Next, We used the log10 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 java 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]));
		}
	}
}
Java log10 Function 2

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

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

Next, We used the 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 condition is True, statement inside the for loop 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 Java log10 Function directly inside the System.out.format statement. Here, the Jcompiler will call the Math.log10 method (static double log10(double number)) 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 log10 program, we are going to declare an ArrayList of double type and find the base 10 logarithmic value of list elements.

package MathFunctions;

import java.util.ArrayList;

public class Log10MethodOnArrayList {
	public static void main(String[] args) {
		
		ArrayList<Double> logList = new ArrayList<Double>(5);
		logList.add(1245.998);
		logList.add(-1480.05);
		logList.add(250.9876);
		logList.add(170.01);
		logList.add(2016.98);
		logList.add(-8978.1898);
		
		for (double x : logList) {
			System.out.println("Logarithmic Value of ArrayList =  " + Math.log10(x));
		}
	}
}
Java log10 Function 3

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

ArrayList<Double> logList = new ArrayList<Double>(5);
logList.add(1245.998);
logList.add(-1480.05);
logList.add(250.9876);
logList.add(170.01);
logList.add(2016.98);
logList.add(-8978.1898);

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

for (double x : logList) {

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

System.out.println("Logarithmic Value of ArrayList =  " + Math.log10(x));

Filed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021ยท All Rights Reserved by Suresh.
About | Contact | Privacy Policy