- : Java int Integer.MAX_VALUE (2147483647). , Integer.MIN_VALUE, . :
public class IntegerOverflow {
public static void main(String[] args) {
int i = Integer.MAX_VALUE;
System.out.println("i = Integer.MAX_VALUE: " + i);
System.out.println("i + 1: " + (i + 1));
System.out.println("i + 2: " + (i + 2));
}
}
, , java.math.BigInteger:
import java.math.BigInteger;
public class BigIntegerExample {
public static void main(String[] args) {
BigInteger b = BigInteger.valueOf(Long.MAX_VALUE);
System.out.println("b = Long.MAX_VALUE: " + b);
System.out.println("b**2: " + b.multiply(b));
System.out.println("b**3: " + b.pow(3));
System.out.println("b**10: " + b.pow(10));
}
}
. , . ,