Des*_*tes 13 java modulo modulus long-integer
如何在Java中找到两个长值的模数(%)?我的代码说'整数太大'后跟我想要修改的数字.我尝试将它投入很长时间但它没有用.我是否必须将其转换为BigInteger并使用余数方法?谢谢.
您只能有一个最大为2147483647的整数。如果要大于此整数,例如30亿,则必须将其指定为长整数。
class Descartes {
public static void main(String[] args) {
long orig = Long.MAX_VALUE;
long mod = orig % 3000000000; // ERROR 3000000000 too big
long mod = orig % 3000000000L; // no error, specified as a long with the L
}
}
Run Code Online (Sandbox Code Playgroud)
请记住,您可以使用大写或小写L,但建议使用大写,因为小写看起来与数字1非常相似。