Ad

No need to declare number outside of for loop.

Code
Diff
  • public class CountTheDigit {
    	public static int nbDig(int n, int d) {
        int count=0;
        for(int i=0; i<n; i++) {
    			String number=(i*i)+"";
    			count +=  number.length() - number.replace(d+"", "").length();
    	  }
      	return count;
      }
    }
    • 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)+"";
    • String number=(i*i)+"";
    • count += number.length() - number.replace(d+"", "").length();
    • }
    • return count;
    • }
    • }