integer log base 10 function without using java.lang.Math? I am assigned to a task of creating a function int logBase10Estimate(int n) that returns the log of a number base 10. The answer is integer part only.(w/o using the Math class)

Is this okay?

static int logBase10Estimate(int n){
    int count = 0;
    for(int x = 10; ;x*=10){
        if(x &lt; n){
            count+=1;
            System.out.println(x);
        }
        else if(x == n){
            count+=1;
            break;
        }
        else{
            break;
        }
    }   
    return count;
}
You have the possibility of an infinite loop.

Consider: logBase10Estimate(2147483647). Should be about 9.  We need a value of \$10^i\$ which is greater than 1000000000.  So, what values does x take on?

         10
        100
       1000
      10000
     100000
    1000000
   10000000
  100000000
 1000000000
 1410065408
 1215752192
 -727379968
 1316134912
  276447232
-1530494976
 1874919424
 1569325056
-1486618624
  :  :  :


Any value of num greater than 1000000000 is going to give incorrect results.  And some values, like 2147483647 will never give an answer, because no int value is greater than it, and x will never be odd, so it will never be equal to it either.

Not only is slepic's solution cleaner, it is correct and it terminates for all values.