Java中longs的模运算符是什么? [英] What is the modulo operator for longs in Java?
本文介绍了Java中longs的模运算符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中找到两个长值的模数(%)?我的代码说整数太大,后跟我试图修改的数字。我尝试将它投入很长时间但它没有用。我是否必须将其转换为BigInteger并使用余数方法?谢谢。
How do I find the modulo (%) of two long values in Java? My code says 'Integer number too large' followed by the number I'm trying to mod. I tried casting it to a long but it didn't work. Do I have to convert it to a BigInteger and use the remainder method? Thanks.
推荐答案
%
运算符适用于long。听起来你可能忘记在数字文字的末尾贴上 L
,如 123456789L
。我们能看到您的代码吗?
The %
operator does work for longs. It sounds like you may have forgotten to stick L
at the end of a numeric literal, as in 123456789L
. Can we see your code?
这篇关于Java中longs的模运算符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文