1 Public classTest4 {2 Public Static voidMain (string[] args) {3BigInteger num1=NewBigInteger ("123456789123456789123456789");4BigInteger num2=NewBigInteger ("2345678901234567890");5System.out.println ("Plus:" +(Num1.add (num2)));6System.out.println ("Minus:" +(Num1.subtract (num2)));7System.out.println ("Multiply:" +(Num1.multiply (num2)));8System.out.println ("except:" +(Num1.divide (num2)));9System.out.println ("modulo:" +(Num1.remainder (num2)));TenBiginteger[] Num3=(Num1.divideandremainder (num2)); One for(BigInteger big:num3) { ASystem.out.println ("quotient and remainder" +big); - } - theBigDecimal num4=NewBigDecimal ("999999999999999999999999999999999999.999999999999999999"); -BigDecimal num5=NewBigDecimal ("8999999999999999999999999999999999999999999.999999999999"); - -System.out.println ("and:" +(Num4.add (NUM5))); +System.out.println ("Minus:" +(Num4.subtract (NUM5))); -System.out.println ("Multiply:" +(Num4.multiply (NUM5))); +System.out.println ("except:" + (Num4.divide (num5,5, Bigdecimal.round_half_down))); A at } -}
In some projects that require large numbers of calculations, two commonly used classes are available in Java to manipulate large numbers
Large numbers operation, BigInteger use BigDecimal (Very large decimals)