Ad
Code
Diff
  • public class CountTheDigit {
    
      public static int count(int num, int digit) {
        int result = 0;
        
        do {
          if (num % 10 == digit)
            ++result;
          num /= 10;
        } while (num != 0);
        
        return result;
      }
      
    	public static int nbDig(int n, int d) {
        int result = 0;
        
        for(int i = 0; i < n; ++i)
    			result += count(i * i, d);
        
      	return result;
      }
    }
    • public class CountTheDigit {
    • public static int count(int num, int digit) {
    • int result = 0;
    • do {
    • if (num % 10 == digit)
    • ++result;
    • num /= 10;
    • } while (num != 0);
    • return result;
    • }
    • 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;
    • int result = 0;
    • for(int i = 0; i < n; ++i)
    • result += count(i * i, d);
    • return result;
    • }
    • }