Java中Integer的最大值和最小值

时间:2016-08-11 15:56:17   收藏:0   阅读:1564

从JDK1.0开始,Integer中就定义了MIN_VALUEMAX-VALUE两个常量:

/**
 * A constant holding the minimum value an {@code int} can
 * have, -2<sup>31</sup>.
 */public static final int   MIN_VALUE = 0x80000000;

/**
 * A constant holding the maximum value an {@code int} can
 * have, 2<sup>31</sup>-1.
 */public static final int   MAX_VALUE = 0x7fffffff;

Q1:谁能给解释一下,这两个常量为什么会分别定义成0x800000000x7fffffff
Q2:java.lang.String的最大长度是多少?
Q3:如下代码能抛出异常吗?为什么

int x = Integer.MAX_VALUE+10;
if(x >= Integer.MAX_VALUE || x <= Integer.MIN_VALUE){ //throw exception}


来自为知笔记(Wiz)


评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!