- Java.math 包其他内容
- Java.math - 枚举
- Java.math - 讨论
Java.math.BigInteger.divideAndRemainder() 方法
说明
java.math.BigInteger.divideAndRemainder(BigInteger val) 返回两个 BigInteger 组成的数组,包含 (this / val) 和 (this % val)。
声明
以下是 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
java_math_biginteger.htm
广告