In Java, casting takes precedence over division: http://introcs.cs.princeton.edu/java/11precedence/. This means that the statement can be broken down as follows:
- Truncate
a_float
(basically take the floor and store as anint
) - Do integer division by
an_int
- Assign the resulting
int
value tox
If you want an_int
to be promoted to a float
before the operation, then do the division, omit the cast. The result will be a float
(which you can than truncate back into an int
before assignment):
int x = (float)(a_float / an_int);
is the same as
int x = (float)(a_float / (float)an_int);
You can also read this site for a pretty good explanation of what it all means: http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/04/mixed.html