Sum of digits of all 4-digit numbers divisible by 7 What would be the way to approach this problem?
 A: One way to do it is to look at the underlying pattern of when each digit changes as you count up from the first to the last number in the series.  I'll do it for the thousands digit, and you can try the rest.  You'll need to think about each one separately.
The first one is $1001$, and the last is $9996$.
Doing this with a computer is easy.  Doing this by hand is straightforward but you'll need to watch details.  There are lots of opportunities to be off by one.
The first number divisible by $7$ in each thousand is:
$$1001, 2002, 3003, 4004, 5005, 6006, 7000, 8001, 9002,$$
and the last is just seven minus the first of the next thousand:
$$1995, 2996, 3997, 4998, 5999, 6993, 7994, 8995, 9996.$$
There are $143$ terms in the series from $1001$ to $1995$.  Similarly for all of the other thousands except the $6000$'s, where there are $142$ terms.  (This should be clear from inspection of the difference of the first and last in each thousand.  This difference in all but the $6000$'s is $994$ but in the $6000$'s the difference is $987$.)
So, the sum of all of the thousands digits is $(143 \times 45) - 6 = 6429.$
Work out a similar analysis for the other three digits.  Each one has a pattern. 
A: Programmatically this can be solved as follows:
long sum = 0;

for (int i = 1000; i < 9999; i++)
    if (i % 7 == 0) {
        print(" "+i);
        sum+=i;
    }

which gives the following result:
7071071
where % suppose to mean $modulo$

Edit: Sorry, you are right @John
For given problem, this is correct computation:
long sum = 0;

for (int n = 1000; n <= 9999; n++)
    if (n % 7 == 0)
        sum += digitSum(n);

the recursive digitSum method:
static int digitSum(int n) {
    if (n == 0)
        return 0;
    return n%10 + digitSum(n/10);
}

the result is: 23792
