Calculate Logn base r – Java Implementation

Objective: Given a number n and r, write a program to calculate Logrn


N = 32, r =2
Log232= 5

N = 64, r = 4
Log464= 3


Without using built-In function-

  • Initialize result = 0.
  • Keep dividing the given number by r till number is greater than 0 and add one to the result if n is greater than equal to 1.

Java Code:


Log64 with base 4 value: 3.0

Using built-In function-

  • Use Java built in function to compute.

Java Code:


Log64 with base 4 value: 3.0

Top Companies Interview Questions..-

Google Microsoft Amazon Facebook more..

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: