Java.math.BigInteger.intValue() 方法
描述
java.math.BigInteger.intValue() 将此 BigInteger 转换为 int。 这种转换类似于从 long 到 int 的缩小原始转换。
如果此 BigInteger 太大而无法放入 int,则仅返回低 32 位。 此转换可能会丢失有关 BigInteger 值的整体大小的信息,并返回带有相反符号的结果。
声明
以下是 java.math.BigInteger.intValue() 方法的声明。
public int intValue()
指定者
Number 类中的intValue。
参数
NA
返回值
此方法返回转换为 int 的 BigInteger。
异常
NA
示例
下面的例子展示了 math.BigInteger.intValue() 方法的使用。
package com.tutorialspoint;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
// create 2 BigInteger objects
BigInteger bi1, bi2;
// create 2 Integer objects
Integer i1, i2;
// assign values to bi1, bi2
bi1 = new BigInteger("123");
bi2 = new BigInteger("9888486986");
// assign the integer values of bi1, bi2 to i1, i2
i1 = bi1.intValue();
i2 = bi2.intValue();
String str1 = "Integer value of " +bi1+ " is " +i1;
String str2 = "Integer value of " +bi2+ " is " +i2;
// print i1, i2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Integer value of 123 is 123 Integer value of 9888486986 is 1298552394

