Extracted method to count occurrences of each digit in an integer