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\$ – greybeard Apr 1 '20 at 14:08int count = 0; for(; n; n/=10) { ctr++; } return count;
? \$\endgroup\$ – S.S. Anne Apr 1 '20 at 14:20round(sqrt(10))=3
btw ;) \$\endgroup\$ – slepic Apr 1 '20 at 14:203
does not tell why/how it was chosen.) \$\endgroup\$ – greybeard Apr 1 '20 at 14:22