public class CountTheDigit {
public static int nbDig(int n, int d) {
String number ="";
int count=0;
for(int i=0; i<n; i++) {
number=(i*i)+"";
count += number.length() - number.replace(d+"", "").length();
}
return count;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals(CountTheDigit.nbDig(5750, 0), 4697);
}
}