Java.math.BigInteger.divideAndRemainder() 方法
描述
java.math.BigInteger.divideAndRemainder(BigInteger val) 返回包含 (this / val) 后跟 (this % val) 的两个 BigInteger 的数组。
声明
以下是 java.math.BigInteger.divideAndRemainder() 方法的声明。
public BigInteger[] divideAndRemainder(BigInteger val)
参数
val − 此 BigInteger 将被除以的值,并计算余数。
返回值
该方法返回一个由两个 BigInteger 组成的数组:商 (this / val) 是初始元素,余数 (this % val) 是最终元素。
异常
ArithmeticException − 如果 val 为零。
示例
下面的例子展示了 math.BigInteger.divideAndRemainder() 方法的使用。
package com.tutorialspoint;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
// create 2 BigInteger objects
BigInteger bi1, bi2;
bi1 = new BigInteger("-100");
bi2 = new BigInteger("3");
// BigInteger array bi stores result of bi1/bi2
BigInteger bi[] = bi1.divideAndRemainder(bi2);
// print quotient and remainder
System.out.println("Division result");
System.out.println("Quotient is " + bi[0] );
System.out.println("Remainder is " + bi[1] );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Division result Quotient is -33 Remainder is -1

