×

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

String vs StringBuilder

String vs StringBuilder In this section, we will discuss the comparison between Java String and StringBuilder class. String In Java, a string is treated as an object that represents a sequence of characters....

4 minutes read.

Java Math rint() Method

The rint() method of Java Math class returns the double value which is close to the specified argument and is equal to mathematical integer. Syntax: public static double rint(double a) Parameters: The parameter ‘a’...

1 minute read.

Recursion Program in Java

The recursion program in Java demonstrates the usage of recursion. The process by which a function/ method calls itself, again and again, is called recursion. Each recursive call is pushed...

10 minutes read.

URLConnection class in Java

A communication channel between the URL and the program is represented by the Java URLConnection class. It may be utilized to read from and write to the given resource the...

4 minutes read.

How to Split the String in Java with Delimiter

In Java, splitting strings is a significant and typically used activity while coding. Java gives different ways of dividing the String. The most widely recognized way is to use the...

3 minutes read.

Java Stringjoiner Class

StringJoiner is a class which is used to construct a sequence of characters which are separated by a delimiter. Optionally, it starts with a provided prefix and ended with the...

5 minutes read.

How to Convert char to int in Java

How to Convert char to int in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

3 minutes read.

Array Slicing in Java

Array slicing is a method in Java for obtaining a subarray of a specified array. Assume a[] is an array. It contains eight items indexed from a[0] to a[7].a[] =...

3 minutes read.

Number Pattern Programs in Java

Number Pattern Programs in Java: Number pattern programs are part of pattern programs. In the previous section, we have learned the approach to print the pattern program in Java. To...

6 minutes read.

The final Keyword in Java

The final keyword is employed in several instances. Firstly, the non-access modifier final only applies to variables, methods, and classes. The final can be used in the following situations. Final Variables When...

6 minutes read.

Program to Reverse a Number in Java

In order to reverse a number, the digit in the first place must be swapped with the digit in the final position, the second digit with the second-to-last digit, and...

3 minutes read.

How to Reverse a String in Java

How to Reverse a String in Java There are a lot of ways to reverse a string in Java. One can use iteration, StringBuilder, StringBuffer to do the reverse of a...

6 minutes read.

Java Implements Keyword

To understand about the keyword implements we need to learn about the concept of the interfaces and inheritance in java programming languages. So let us learn about the interface and...

3 minutes read.

Java Set Interface

We use set when we don't want to allow duplicate entries. All Set implementations do not allow duplicates. HashSet: This class stores its elements in hash tables. It uses the hashCode()...

3 minutes read.

Tribonacci series in Java

The Fibonacci series and the Tribonacci sequence are linked. The Fibonacci sequence, each element summates the three preceding terms, is expanded into the Tribonacci series in Java. Through specific examples,...

3 minutes read.

Java Math multiplyFull() Method

The multiplyFull() method of Math class returns the exact product of the arguments. Syntax: public static long multiplyFull (int x, int y) Parameters: The parameters ‘x’ and ‘y’ represent the first value and second...

1 minute read.

Spliterator in Java 8

In this tutorial, we will understand the meaning of spliterator in java 8. It is just like any other iterator available in java used to traverse the elements of either...

4 minutes read.

Java Get File Size

There are three ways to get the file size in Java. Using Java InputOutput Using NewInputOutput Library Files.size() Method FileChannel.size() Method Using Apache Commons InputOutput Using Java InputOutput: The Java IO package offers the classes that deal...

5 minutes read.

Types of Sockets in Java

The fundamental idea behind Java's networking capability is the socket. Early in the 1980s, the Berkeley UNIX 4.2BSD version included the socket paradigm. Berkeley socket is the term employed as...

9 minutes read.

Java Integer getInteger() method

The getInteger() method of Integer class determines the integer value of the system property with the given name. Syntax` public static Integer getInteger(String nm) Parameters The parameter ‘nm’ represents the property name. Throws The getInteger ()...

1 minute read.