java之BigInteger类

BigInteger类可以让超过Integer范围的数据进行运算;

构造方法:
  public BigInteger(String al)

成员方法:
  public BigInteger add(BigInteger val) 加
  public BigInteger subtract(BigInteger val) 减
  public BigInteger multiply(BigInteger val) 乘
  public BigInteger divide(BigInteger val) 除
  public BigInteger[] divideAndRemainder(BigInteger val) 取商和余数

1
public class Demo4_BigInteger { 2 3 public static void main(String[] args) { 4 5 BigInteger bi1 = new BigInteger("100"); 6 BigInteger bi2 = new BigInteger("2"); 7 8 System.out.println(bi1.add(bi2)); // 9 System.out.println(bi1.subtract(bi2)); // 10 System.out.println(bi1.multiply(bi2)); // 11 System.out.println(bi1.divide(bi2)); // 12 13 BigInteger[] bi3 = bi1.divideAndRemainder(bi2); //求商和余数 14 for (int i = 0; i < bi3.length; i++) { 15 System.out.println(bi3[i]); 16 } 17 } 18 }

猜你喜欢

转载自www.cnblogs.com/jiangjunwei/p/9196982.html