Write a Java program to extract the primitive type value from a given BigInteger value
- برمجة جافا
- برمجة
- 2021-05-01
- razanmazen8711884270
الأجوبة
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
BigInteger bigval = BigInteger.valueOf(Long.MAX_VALUE);
System.out.println("\nBigInteger value: "+bigval);
long val_Long = bigval.longValue();
System.out.println("\nConvert the said BigInteger to an long value: "+val_Long);
int val_Int = bigval.intValue();
System.out.println("\nConvert the said BigInteger to an int value: "+val_Int);
short val_Short = bigval.shortValue();
System.out.println("\nConvert the said BigInteger to an short value: "+val_Short);
byte val_Byte = bigval.byteValue();
System.out.println("\nConvert the said BigInteger to byte: "+val_Byte);
long val_ExactLong = bigval.longValueExact();
System.out.println("\nConvert the said BigInteger to exact long: "+val_ExactLong);
}
}
Sample Output:
BigInteger value: 9223372036854775807 Convert the said BigInteger to an long value: 9223372036854775807 Convert the said BigInteger to an int value: -1 Convert the said BigInteger to an short value: -1 Convert the said BigInteger to byte: -1 Convert the said BigInteger to exact long: 9223372036854775807
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال