1. BigInteger加减乘除法的使用
1 public BigInteger add(BigInteger val):加 2 public BigInteger subtract(BigInteger val):减 3 public BigInteger multiply(BigInteger val):乘 4 public BigInteger divide(BigInteger val):除 5 public BigInteger divideAndRemainder(BigInteger val):返回 商 和 余数的数组
2. 代码示例:
1 package cn.itcast_02; 2 3 import java.math.BigInteger; 4 5 /* 6 * public BigInteger add(BigInteger val):加 7 * public BigInteger subtract(BigInteger val):减 8 * public BigInteger multiply(BigInteger val):乘 9 * public BigInteger divide(BigInteger val):除 10 * public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组 11 */ 12 public class BigIntegerDemo { 13 public static void main(String[] args) { 14 BigInteger bi1 = new BigInteger("100"); 15 BigInteger bi2 = new BigInteger("50"); 16 17 // public BigInteger add(BigInteger val):加 18 System.out.println("add:" + bi1.add(bi2)); 19 // public BigInteger subtract(BigInteger val):加 20 System.out.println("subtract:" + bi1.subtract(bi2)); 21 // public BigInteger multiply(BigInteger val):加 22 System.out.println("multiply:" + bi1.multiply(bi2)); 23 // public BigInteger divide(BigInteger val):加 24 System.out.println("divide:" + bi1.divide(bi2)); 25 26 // public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组 27 BigInteger[] bis = bi1.divideAndRemainder(bi2); 28 System.out.println("商:" + bis[0]); 29 System.out.println("余数:" + bis[1]); 30 } 31 }
运行效果如下:
时间: 2024-10-05 12:27:17