Q:

Why does this not result in 1000?

Possible Duplicate:
Java problem-Whats the reason behind and what will be probable output 

long milli=24*60*60*1000;
long micro=24*60*60*1000*1000;
long result=micro/milli;

The result should be 1000 but its not. Why does it work when I use 24*60*60*1000*1000L?
Can someone tell me the reason for this?

A:

The trouble is that the calculation is done on ints and then casted to long, and unfortunately 24*60*60*1000*1000 won't fit in an int and wraps around. You could do something like
long micro=24L*60*60*1000*1000;

to force the last multiplication to be done on longs.

A:

Easy, if you know, but always a surprise ;)
The literal 1000 is an int value, so the multiplaction is done with integers and not with longs. 
long micro=24*60*60*1000*1000;

is interpreted like
long micro = (long) ((int) 24*60*60*1000*1000);

which is 500654080 instead of 86400000000
Use at least one long literal in your expression, this forces the whole calculation to be done in long:
long milli=24*60*60*1000;
long micro=24*60*60*1000*1000 * 1L; // forces a calculation in long
long result=micro/milli;

