×

Java Math log10() Method

The log10() method of Math class returns the base 10 logarithmic value for the specified double argument.

Syntax:

public static double log10(double a)

Parameters:

The parameter ‘a’ represents a double value.

Return Value:

The log10() method returns the base 10 logarithm of a.

Special cases of the log10() method are as follows:

  • It returns NaN, if the argument is NaN or less than zero.
  • It returns positive infinity, if the argument passed is positive infinite.
  • It returns negative infinity, if the argument passed is positive zero or negative zero.
  • It returns n, if the argument is equal to 10n for integer n.

Example 1:

public class JavaMathLog10Example1 {
    public static void main(String[] args) {
        double a = 10;
        //returns the natural base 10 logarithm of a
        System.out.println("Logrithm10 value  : "+Math.log10(a));
    }
}

Output:

Logrithm10 value  : 1.0

Example 2:

public class JavaMathLog10Example2 {
    public static void main(String[] args) {
        double a = -98;
        //returns NaN, if the argument is NaN or less than zero
        System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a));
    }
}

Output:

Logrithm10 value for -98.0 : NaN

Example 3:

public class JavaMathLog10Example3 {
    public static void main(String[] args) {
        double a = 98/0.0d;
        //returns positive infinity, if the argument passed is positive infinite
        System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a));
    }
}

Output:

Logrithm10 value for Infinity : Infinity

Example 4:

public class JavaMathLog10Example4 {
    public static void main(String[] args) {
        double a = 0;
        //returns negative infinity, if the argument passed is positive or negative zero
        System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a));
    }
}

Output:

Logrithm10 value for 0.0 : -Infinity

Example 5:

public class JavaMathLog10Example5 {
    public static void main(String[] args) {
        double a = 100000000;
        //returns n, if the argument is equal to 10n for integer n
        System.out.println("Logrithm10 value for "+a +" : "+Math.log10(a));
    }
}

Output:

Logrithm10 value for 1.0E8 : 8.0

Related Topics

Getting Synchronized Set from Java HashSet

The synchronizedSet() technique for java.util.Collections class is utilized to return a synchronized (string safe) set supported by the predetermined set. To ensure sequential access, it is important that everything admittance...

4 minutes read.

How to compare two dates in different format in Java?

We need to compare two dates frequently when coding. Real-world examples include sorting a list of persons by age or keeping track of students' attendance. To compare two dates, we...

7 minutes read.

Hybrid Inheritance in Java

The most crucial OOPs concept in Java is inheritance, which enables the transfer of a class's properties to another class. It describes the Is-A relationship generally. We can create a...

3 minutes read.

Java Socket Programming

Java Socket Programming Socket programming is used for the communication between the applications, i.e., client and server running on different JRE may be connection-oriented or connectionless. The client program can be designed using the...

8 minutes read.

The Diamond Operator in Java 7

The Diamond operator is a comparatively recent Java operator originally developed in JDK 7 to enhance type identification and eliminate boilerplate Java code. The Diamond operator is characterized by a...

2 minutes read.

How to Read XML Files in Java?

Introduction Today, we are going to learn about how to read XML files in java. Before, reading the XML Files let us learn about XML. XML Files The full form of XML is...

8 minutes read.

Java Integer longValue() method

The longValue()  method of Java Integer class returns a long value for this Integer after a widening primitive conversion. Syntax public long longValue() Parameters NA Specified by This method is specified by longValue in class Number Return...

1 minute read.

Abstract Class Program in Java

Abstract Class Program in Java Abstraction is a technique by which a developer hides the implementation details from the user and shows only the functionality.It is not only confined to the...

6 minutes read.

Best Java Security Framework

The security of applications is currently our top concern when creating them. The applications or bits of code running over the network are exposed to dangers and may jeopardize integrity,...

3 minutes read.

Time Class Operation in Java

The Java SQL package includes the time class. This class is merely a lightweight wrapper for java. util. THANKS TO THE recognize BC API can recognize this as a SQL...

3 minutes read.

Java Append Data to File

When writing data to a file using the classes within the java.io package, its file will often be overwritten, meaning that any existing data will be removed and new data...

4 minutes read.

Java Session

Session indicates interval of time. A session is a simple  time interval in which servers and client interacts. To maintain the state of the client or user we use technologies...

5 minutes read.

Frugal number in Java

A frugal number is a positive integer with base b that has more digits than the number of prime factors it can be factored into (including exponents greater than 1)....

3 minutes read.

Snake and Ladder Problem in Java

Find the smallest number of dice throws necessary to reach the destination or last cell from the source or first cell on a snake and ladder board. Essentially, the player...

6 minutes read.

Java FileOutputStream

What is FileOutputStream?When we need raw stream data written into a file, we need to look for another option: FileOutputStream. It is used when the file's data is byte-oriented. It comes under...

4 minutes read.

Permutation Coefficient in Java

In this tutorial, we will get familiar with the permutation coefficient in Java.  We will understand it through examples and see different approaches to solving the problem. A permutation is a...

5 minutes read.

Java Destructors

Before knowing about Java destructors, let us know about constructors. If we understand the concept of the constructor, we can easily understand about destructor and also, we will get an...

3 minutes read.

Equidigital in Java

In this section, we will understand what is an equidigital number and how to write Java programs to locate them. It is commonly asked in academic settings and Java coding...

4 minutes read.

Java calculate age

In this section, we will create a Java program that calculates age from the given date of birth or current date. In order to get the date of birth from the current...

6 minutes read.

Java Integer min() method

The min()  method of Integer class returns the smaller of two int values. It returns the same result as by calling Math.min.  Syntax public static int min(int a, int b) Parameters The parameters ‘a’...

2 minutes read.