A good first start, but far from perfect as it loops through every number between 1 and n. I could improve it slightly by tweaking the start and end points (e.g. starting at 3), but it would still roughly involve n iterations.
My second attempt was this:

int n = 999, total=0;
Set nums = new HashSet();
for (int i=3; i

Note the use of the HashSet to avoid counting duplicates (i.e. numbers divisible by 3 and 5, like 15, 30 etc). Obviously the code could be tidied up but this reduced the number of loop iterations from 999 to 532 (and the run time from ~110ms to ~90ms).

However, the code/algorithm is still imperfect as although it doesn't count numbers divisible by 3 and 5 twice, it still iterates over them twice. I couldn't figure out a way to avoid this, so having met the requirements (I verified the correct answer on the Euler site and, at ~90ms, it runs well under one second), I submitted my answer and started reading the supplied solution.

The 'perfect' solution involves 3 breakthroughs.
The first is that the ideal solution involves using formulae, not iteration.
The second is that in the example of the total all numbers up to 1000 divisible by 3
i.e.
3+6+9+ ... +999
= 3*(1+2+3+...+1000/3)
where 1000 divided by 3 is rounded down.

The 3rd and final breakthrough required is that:
1+2+3+...+y
= (y/2)*(y+1)

I have to admit that I am not sure I would have ever made these break throughs myself!

But using these facts, the ideal solution is along the following lines: