A variant of Nick Berardi's answer that avoids a branch:
int q = records / recordsPerPage, r = records % recordsPerPage;
int pageCount = q - (-r >> (Integer.SIZE - 1));
Note: (-r >> (Integer.SIZE - 1))
consists of the sign bit of r
, repeated 32 times (thanks to sign extension of the >>
operator.) This evaluates to 0 if r
is zero or negative, -1 if r
is positive. So subtracting it from q
has the effect of adding 1 if records % recordsPerPage > 0
.