Java:关于负数的向上转型
int的负数n向上转型为long时,应该写成-(long)n,而不是(long)-n。
举例:
int n = Integer.MIN_VALUE;//-2147483648
System.out.println(-(long)n);//2147483648
System.out.println((long)-n);//-2147483648
int的负数n向上转型为long时,应该写成-(long)n,而不是(long)-n。
举例:
int n = Integer.MIN_VALUE;//-2147483648
System.out.println(-(long)n);//2147483648
System.out.println((long)-n);//-2147483648