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