Java.math.BigInteger.signum()方法实例
java.math.BigInteger.signum() 返回此BigInteger的函数正负号。
声明
以下是java.math.BigInteger.signum()方法的声明
public int signum()
参数
-
NA
返回值
此方法返回-1,0或1作为此BigInteger的值对应是负,零或正数。
异常
-
NA
例子
下面的例子显示math.BigInteger.signum()方法的用法
package com.yiibai; 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 ); } }
让我们编译和运行上面的程序,这将产生以下结果:
Signum function returns 0 for 0 Signum function returns 1 for 10 Signum function returns -1 for -10