为什么-Integer.MIN_VALUE还是等与Integer.MIN_VALUE呢???
今天发现一个奇怪的现象,我根据这个现象写了一个简单的程序:
public class Simple {
public static void main(String[] args) {
int a=Integer.MIN_VALUE;
int b=-a;
if (b==a) {
System.out.println("******b==a*******");
}else{
System.out.println("******b!=a*******");
}
if (b==Integer.MAX_VALUE){
System.out.println("b==Integer.MAX_VALUE");
}else {
System.out.println("b!=Integer.MAX_VALUE");
}
}
}
我知道Integer.MIN_VALUE=-2147483648 而 Integer.MAX_VALUE=2147483647
所以上面程序中b就超出int的范围了,也肯定不等于Integer.MAX_VALUE,
但我的问题是:为什么-Integer.MIN_VALUE还是等与Integer.MIN_VALUE呢???