Home »
Java »
Java Programs
Java program to find the logarithmic value of a number for base 10
Given a number, we have to find the logarithmic value of a number for base 10.
Submitted by Nidhi, on May 13, 2022
Problem statement
In this program, we will read a floating-point number from the user using the Scanner class and find the logarithmic value of the input number for base 10 using the Math.log10() method.
Source Code
The source code to find the logarithmic value of a number for base 10 is given below. The given program is compiled and executed successfully.
// Java program to find the logarithmic value
// of a number for base 10
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner X = new Scanner(System.in);
double num = 0;
System.out.print("Enter number: ");
num = X.nextDouble();
System.out.print("Logarithmic value of num for base 10 is: " + Math.log10(num));
}
}
Output
Enter number: 45.5
Logarithmic value of num for base 10 is: 1.6580113966571124
Explanation
In the above program, we imported the "java.util.*" package to use the Scanner class. Here, we created a public class Main that contains a main() method.
The main() method is the entry point for the program. Here, we created a variable num of double type and read its value from the user using the nextDouble() method of the Scanner class. Then we get the logarithmic value of variable num for base 10 and printed the result.
Java Math Class Programs »