Java Math BigInteger.abs() 方法


Java Math BigInteger.abs() 方法

package com.codingdict;



import java.math.*;



public class BigIntegerDemo {



   public static void main(String[] args) {



      // create 4 BigInteger objects

      BigInteger bi1, bi2, bi3, bi4;  



      // assign values to bi1, bi2

      bi1 = new BigInteger("123");

      bi2 = new BigInteger("-123");



      // assign absolute values of bi1, bi2 to bi3, bi4

      bi3 = bi1.abs();

      bi4 = bi2.abs();



      String str1 = "Absolute value of " + bi1 + " is " + bi3;

      String str2 = "Absolute value of " + bi2 + " is " + bi4;



      // print bi3, bi4 values

      System.out.println( str1 );

      System.out.println( str2 );

   }

}