Write a Java program to Find the logarithmic value of a Number


This program calculates the logarithmic value of a number entered by the user using the Math.log() method in Java. Here's how the program works:

  • The program starts by importing the java.util.* package which contains the Scanner class used for user input.
  • The Logarithmic class is defined with a main method.
  • Inside the main method, a new Scanner object X is created to read user input.
  • A double variable num is initialized to zero.
  • The program prompts the user to enter a number.
  • The number entered by the user is read using the nextDouble() method of the Scanner class and assigned to the num variable.
  • The program then calculates the logarithmic value of the number using the Math.log() method and prints the result to the console using System.out.print().

Source Code

import java.util.*;
public class Logarithmic
{
	public static void main(String[] args)
	{
		Scanner X = new Scanner(System.in);
		double num = 0;
 
		System.out.print("Enter The Number : ");
		num = X.nextDouble();
 
		System.out.print("Logarithmic Value of Number is : " + Math.log(num));
	}
}

Output

Enter The Number : 53
Logarithmic Value of Number is : 3.970291913552122

Example Programs