What is the modulo operator for longs in Java?

Descartes picture Descartes · Apr 21, 2011 · Viewed 30.2k times · Source

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.

Answer

Daniel Lubarov picture Daniel Lubarov · Apr 21, 2011

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?