Home » Java programming language

Java Math Class static double log10(double d) with example

Java Math Class static double log10(double d) method: Here, we are going to learn about the static double log10(double d) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 04, 2019

Math Class static double log10(double d)

  • This method is available in java.lang package.
  • This method is used to return the logarithm of the given (base 10) of the given argument in the method.
  • This is a static method so it is accessible with the class name too.
  • The return type of this method is double, it returns the logarithm (base 10) of the given argument.
  • In this method, we pass only one parameter as the double type whose logarithm (base 10) to be found.
  • This method does not throw any exception.

Syntax:

    public static double log10(double d){
    }

Parameter(s): It accepts a double value, whose logarithm (base 10) to be found.

Return value:

The return type of this method is double, it returns the logarithm (base 10) of the given argument.

Note:

  • If we pass "NaN", it returns "NaN".
  • If we pass an argument which is equal to 10*n (n should be an integer type), it returns the n.
  • If we pass a positive infinity, it returns the same (positive infinity).
  • If we pass zero (-0 or 0), it returns the negative infinity.

Java program to demonstrate example of log10(double d) method

// Java program to demonstrate the example of 
// log10(double d) method of Math Class

public class Log10Method {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double d1 = 7.0 / 0.0;
        double d2 = -0.0;
        double d3 = 6054.2;

        // displaying values
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);

        // Here , we will get (Infinity) because we are 
        // passing parameter whose value is (-infinity)
        System.out.println("Math.log10(d1): " + Math.log10(d1));

        // Here , we will get (-Infinity) because we are 
        // passing parameter whose value is (-0.0)
        System.out.println("Math.log10(d2): " + Math.log10(d2));

        // Here , we will get (log [10 raised to the power of 
        // the given argument]) and we are passing parameter 
        // whose value is (6054.2)
        System.out.println("Math.log10(d1): " + Math.log10(d3));
    }
}

Output

E:\Programs>javac Log10Method.java

E:\Programs>java Log10Method
d1: Infinity
d2: -0.0
d3: 6054.2
Math.log10(d1): Infinity
Math.log10(d2): -Infinity
Math.log10(d1): 3.782056763740091


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.