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 < n){ count+=1; System.out.println(x); } else if(x == n){ count+=1; break; } else{ break; } } return count; }
round(sqrt(10))
.\$\endgroup\$int count = 0; for(; n; n/=10) { ctr++; } return count;
?\$\endgroup\$round(sqrt(10))=3
btw ;)\$\endgroup\$3
does not tell why/how it was chosen.)\$\endgroup\$