Java.math.BigInteger.remainder()方法實例
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