有什么解决办法吗?为什么返回541而不是3。
public class Test {
public static void main(String[] args) {
double a = Math.pow(3, 561);
// it returns 541 instead of 3
System.out.println(a % 561);
}
}
double
s实际上并不表现为整数。Java的真实整数类型是java.math.BigInteger
。
public static void main(String[] args) {
BigInteger a = new BigInteger("3").pow(561);
System.out.println(a.mod(new BigInteger("561")));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句