Ian提供的整数数学解决方案很好,但存在整数溢出错误。假设变量为all
int,则解决方案可以重写为使用
long数学运算并避免错误:
int pageCount = (-1L + records + recordsPerPage) / recordsPerPage;
如果
records为
long,则错误仍然存在。模数解决方案没有错误。
欢迎分享,转载请注明来源:内存溢出
Ian提供的整数数学解决方案很好,但存在整数溢出错误。假设变量为all
int,则解决方案可以重写为使用
long数学运算并避免错误:
int pageCount = (-1L + records + recordsPerPage) / recordsPerPage;
如果
records为
long,则错误仍然存在。模数解决方案没有错误。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)