Java Math BigInteger.signum() 方法


Java Math BigInteger.signum() 方法

package com.codingdict;



import java.math.*;



public class BigIntegerDemo {



   public static void main(String[] args) {



      // create 3 BigInteger objects

      BigInteger bi1, bi2, bi3;



      // create 3 int objects

      int i1, i2, i3;



      bi1 = new BigInteger("0");

      bi2 = new BigInteger("10");

      bi3 = new BigInteger("-10");



      // assign signum results of bi1, bi2, bi3 to i1, i2, i3

      i1 = bi1.signum();

      i2 = bi2.signum();

      i3 = bi3.signum();



      String str1 = "Signum function returns " + i1 + " for " +bi1;

      String str2 = "Signum function returns " + i2 + " for " +bi2;

      String str3 = "Signum function returns " + i3 + " for " +bi3;



      // print i1, i2, i3 values

      System.out.println( str1 );

      System.out.println( str2 );

      System.out.println( str3 );

   }

}