Java.math.BigInteger.mod() 方法
描述
java.math.BigInteger.mod(BigInteger m) 返回一个 BigInteger,其值为 (this mod m)。 此方法与剩余方法的不同之处在于它始终返回非负 BigInteger。
声明
以下是 java.math.BigInteger.mod() 方法的声明。
public BigInteger mod(BigInteger m)
参数
m − 模数。
返回值
该方法返回一个 BigInteger 对象,其值为这个 mod m。
异常
ArithmeticException − 如果 m ≤ 0。
示例
下面的例子展示了 math.BigInteger.mod() 方法的使用。
package com.tutorialspoint;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
// create 3 BigInteger objects
BigInteger bi1, bi2, bi3;
bi1 = new BigInteger("-100");
bi2 = new BigInteger("3");
// perform mod operation on bi1 using bi2
bi3 = bi1.mod(bi2);
String str = bi1 + " mod " + bi2 + " is " +bi3;
// print bi3 value
System.out.println( str );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
-100 mod 3 is 2

