java.math.BigInteger.remainder(BigInteger val) 返回一個BigInteger,其值是 (this % val).
以下是java.math.BigInteger.remainder()方法的宣告
public BigInteger remainder(BigInteger val)
val - 由此BigInteger是進行相除的值,並計算餘數
該方法返回一個BigInteger物件的值是 this % val.
ArithmeticException - if val is zero
下面的例子顯示math.BigInteger.remainder()方法的用法
package com.yiibai; 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 remainder operation on bi1 using bi2 bi3 = bi1.remainder(bi2); String str = bi1 + " % " + bi2 + " is " +bi3; // print bi3 value System.out.println("Remainder result for " +str); } }
讓我們編譯和執行上面的程式,這將產生以下結果:
Remainder result for -100 % 3 is -1